我在向iCarousel" viewForItemAtIndex"添加视图时遇到了问题。方法
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UIView *sub = nil;
//iCarousel *temp;
//create new view if no view is available for recycling
if (view == nil)
{
UIViewController * viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"UIidentifier"];
view = [viewController.view viewWithTag:20];
CGRect Frame = CGRectMake(view.frame.origin.x, view.frame.origin.y + 100, view.frame.size.width, view.frame.size.height);
view.frame = Frame;
}
UILabel *label=(UILabel*)[view viewWithTag:23];
label.text = [[listOfAnimalsNames objectAtIndex:index]nameOfTheCompanie];
return view;
}
我想展示一个UIView" mockUp"并使用"索引"填充标签中的一些数据。在iCarousel中,我创建了自己的UIViewController,其中包含" mockup" UIView的。问题是,当我调用这个UIView时(如在代码中)没有任何反应。 (我在加载数据后使用reloadData方法)
答案 0 :(得分:0)
为什么每个视图都需要自己的ViewController?它们都应该由控制iCarousel视图(或至少它的数据源)控制。此外,UILabel只应实例化一次。
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UIView *sub = nil;
if (view == nil)
{
view = [UIView alloc] initWithFrame:CGRectMake(...);
UILabel *label=[[UILabel alloc] initWithFrame:(...)];
[view addSubview:label];
}
label.text = [[listOfAnimalsNames objectAtIndex:index]nameOfTheCompanie];
return view;
}