【问题标题】:iCarousel with UIScrollViews带有 UIScrollViews 的 iCarousel
【发布时间】:2012-07-16 01:01:22
【问题描述】:

有人知道如何将 uiscrollviews 对象放入 iCarousel 中吗? 我的意思是 IBOutlet 对象。

所以我尝试了这种方式:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index 
{
UIScrollView *scroll = [UIScrollView alloc] initWithFrame...
scroll.contentSize =..
scroll.backgroundColor = ..
return scroll;
}

它可以工作,但我需要在轮播中放入一组 uiscrollviews(带有很多按钮),这是我用 IBuilder 制作的。

我也是这样弄的:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index 
{
UIScrollView *scroll = [scrollArray objectAtIndex:index];
return scroll;
}

但是没有用。

【问题讨论】:

  • 滚动视图是否与轮播在同一个 nib 文件中,还是每个都在它自己的 nib 中?您如何将滚动视图放入您的数组中 - 它是 IBoutletCollection 吗?
  • 我创建了 3 个名为 scroll1、scroll2、scroll3 的 nib 文件,然后尝试这样做 - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)查看 { for (int i = 1; i
  • 你应该使用 view = [[[NSBundle mainBundle] loadNibNamed:[titleArray objectAtIndex:i] owner:self options:nil] objectAtIndex:0];
  • 数组是零索引的,你总是想要 nib 文件中的第一个项目,而不是匹配项目索引的那个。
  • 对不起,尼克,它不起作用,我试过这样:view = [[[NSBundle mainBundle] loadNibNamed:[titleArray objectAtIndex:index] owner:self options:nil] objectAtIndex:0];

标签: uiscrollview icarousel


【解决方案1】:

这是正确的做法:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view

    NSString *nibName = [NSString stringWithFormat:@"scroll%i", index + 1];
    NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil];
    view = [nibContents objectAtIndex:0];
    return view;
}

【讨论】:

  • 谢谢你的帮助,尼克,但我很害怕;就像:view = [[[NSBundle mainBundle] loadNibNamed:[titleArray objectAtIndex:index+1] owner:self options: nil] objectAtIndex:0];
  • 所以为了清楚起见,您将返回 3 作为 numberOfItems,并且您有 3 个 nib,名为 scroll1.xib、scroll2.xib 和 scroll3.xib,每个都包含一个滚动视图,每个都不同, 对?我想也许你应该通过 github 联系我,我会进一步调查,因为你描述的问题没有多大意义。
  • 完全正确,尼克。我会从一开始再尝试一次,如果问题不会消失,我会联系你,谢谢!
猜你喜欢
  • 2010-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-03
  • 2014-02-13
  • 1970-01-01
相关资源
最近更新 更多