0

出于某种原因,当我设置时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;
}
4

1 回答 1

0

我认为问题可能来自journalCarouselItems数组的初始声明。该错误消息意味着您正在将 objectAtIndex: 消息发送到 NSString 类型的对象(或者可能是 CFString)。然后,您期望您journalCarouselItems成为一个数组,但它可能被释放得太早(几乎可以肯定是自动释放),并且当上述方法被称为journalCarouselItems现在指向的内存时,它拥有不同的东西。

尝试retain在其声明的最后对数组进行 ing,以确保它位于正确的内存位置。

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] retain];
于 2013-02-06T16:29:14.180 回答