出于某种原因,当我设置时iCarousel.type = iCarouselTypeLinear
,我不能使用超过 6 张图像。当我尝试滚动时,出现以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0xa47c2b0'
我错过了什么?
任何帮助将不胜感激。
控制器代码:
journalCarouselItems = [NSMutableArray arrayWithObjects:
[UIImage imageNamed:@"Icon-JCO1.png"],
[UIImage imageNamed:@"Icon-JCO2.png"],
[UIImage imageNamed:@"Icon-JCO3.png"],
[UIImage imageNamed:@"Icon-JCO4.png"],
[UIImage imageNamed:@"Icon-JCO5.png"],
[UIImage imageNamed:@"Icon-JCO6.png"],
[UIImage imageNamed:@"Icon-JCO7.png"],
[UIImage imageNamed:@"Icon-JCO8.png"],
[UIImage imageNamed:@"Icon-JCO9.png"],
[UIImage imageNamed:@"Icon-JCO10.png"],
[UIImage imageNamed:@"Icon-JCO11.png"],
nil];
// Initialize and configure the carousel
carouselId = 2;
journalCarousel = [[iCarousel alloc] initWithFrame: CGRectMake ( 10, 340, 748, 240)];
journalCarousel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
journalCarousel.type = iCarouselTypeLinear;
journalCarousel.delegate = self;
journalCarousel.dataSource = self;
[self.view addSubview:journalCarousel];
编辑:在调试时,我注意到当我有 6 个图像时,每次都会调用下面的函数并且索引值从 0 变为 5,但是当我有超过 6 个图像时,不会为每个图像调用相同的函数,索引值是 0,2,8,9。
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(ReflectionView *)view
{
UIImage *image = [journalCarouselItems objectAtIndex:index];
UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)] autorelease];
[button setBackgroundImage:image forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.titleLabel.font = [button.titleLabel.font fontWithSize:50];
button.layer.cornerRadius = 8.0f;
button.tag=index;
[view addSubview:button];
return view;
}