2013-02-05 36 views
0

我想一個iCarousel添加到下面的代碼現有的項目,但我得到這個錯誤:MemberCatalog[14990:1a903] -[MainViewController carousel:viewForItemAtIndex:reusingView:]: unrecognized selector sent to instance 0xa0589b0.iCarousel問題

在iCarousel.m引發錯誤的行是:view = [_dataSource carousel:self viewForItemAtIndex:index reusingView:[self dequeueItemView]];

任何幫助它會真的很感激它。

carouselItems = [NSArray arrayWithObjects: 
     [UIImage imageNamed:@"iLibrary+Featured_AM-RAH.png"], 
     [UIImage imageNamed:@"iLibrary+Featured_CCA.png"], 
     [UIImage imageNamed:@"iLibrary+Featured_GI-PA.png"], 
     nil]; 

// Initialize and configure the carousel 
    carousel = [[iCarousel alloc] initWithFrame:self.view.bounds]; 
    carousel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
    carousel.type = iCarouselTypeCoverFlow2; 
carousel.delegate = self; 
carousel.dataSource = self; 

    [self.view addSubview:carousel]; 

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index 
{ 
    UIImage *image = [carouselItems 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.tag=index; 
    return button; 

} 
+0

你執行'-carousel:viewForItemAtIndex:reusingView:'在所有? –

+0

是的。我做了: - (UIView *)旋轉木馬:(iCarousel *)旋轉木馬viewForItemAtIndex:(NSUInteger)索引 { \t UIImage * image = [carouselItems objectAtIndex:index]; \t的UIButton *按鈕= [[[UIButton的頁頭] initWithFrame:方法CGRectMake(0,0,image.size.width,image.size.height)]自動釋放]; \t [按鈕了setBackgroundImage:圖像forState:UIControlStateNormal]; \t [按鈕setTitleColor:的UIColor blackColor] forState:UIControlStateNormal]; \t button.titleLabel.font = [button.titleLabel.font fontWithSize:50]; \t button.tag = index; \t return button; \t } –

+0

嗯,這方法顯然是缺少'reusingView:'部分 –

回答

2

你實現-carousel:viewForItemAtIndex:方法,但認爲需要一個-carousel:viewForItemAtIndex:reusingView:方法。

您需要更新與reusingView:(UIView *)view參數的方法,你會沒事的。您還應該使用該可重用視圖,而不是分配越來越多的視圖,但那是另一回事。