2013-02-06 49 views
0

由於某些原因,當我設置iCarousel.type = iCarouselTypeLinear時,我無法使用超過6張圖片。當我嘗試滾動時,出現以下錯誤: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

您可以發佈控制器代碼,以便我們可以看到代碼中可能出現錯誤嗎?現在我們只是有一個錯誤,沒有代碼看,這是沒有用的。 – Walls

+0

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]; –

回答

0

我認爲這個問題可能來自journalCarouselItems數組的初始聲明。那個錯誤信息意味着你發送一個objectAtIndex:消息給NSString類型的對象(或者CFString)。然後,您將journalCarouselItems作爲一個數組,但它可能過早發佈(幾乎肯定是autoreleased),並且在上述方法被調用時,journalCarouselItems指向的內存現在擁有不同的內容。

嘗試retain在聲明的最後一個數組,以確保它保持在正確的內存位置。

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];