由于某些原因,当我设置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;
}
答案 0 :(得分:0)
我认为问题可能来自journalCarouselItems
数组的初始声明。该错误消息意味着您正在向一个NSString类型的对象(或可能是CFString)发送一个objectAtIndex:消息。然后你要将你的journalCarouselItems
视为一个数组,但它可能过早发布(几乎肯定是自动释放的),并且当上面的方法被称为{{1}所指向的内存时现在拥有不同的东西。
在声明的最后尝试journalCarouselItems
数组,以确保它保持在正确的内存位置。
retain