2014-09-02 2 views
0

Я отправляю данные в коллекцию, но я получаю сообщение об ошибке [__NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance. Пожалуйста, помогите мне. Спасибо.CollectionView данные не отображаются

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 

    // NSURL *imageURL = [NSURL URLWithString:str1]; 
    // NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; 
    // UIImage *image = [UIImage imageWithData:imageData]; 
    // thumbnailImgView.image = image; 


    static NSString *identifier = @"Cell"; 

    CustomCell *cell = (CustomCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 

    UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100]; 
    recipeImageView.image = [UIImage imageNamed:[recipeImages[indexPath.section] objectAtIndex:indexPath.row]]; 
    cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img.png"]]; 
    cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"One-Album.png"]]; 

    return cell; 

} 
+0

Можете ли вы показать мне код, в котором вы заполняете 'recipeImages'? – avismara

+0

- (void) viewDidLoad { [super viewDidLoad]; recipeImages = [NSArray arrayWithObjects: @ "img.png", @ "One-Album.png", @ "Create-Album.png", @ "AllPhotos.png", @ "Albums.png", @ "яркость1 .png ", @" original1 (1) .png ", @" crop1.png ", ноль]; // Выполняйте любую дополнительную настройку после загрузки представления. } – Chenna

+0

- (NSInteger) numberOfSectionsInCollectionView: (UICollectionView *) collectionView { return 1; } - (NSInteger) collectionView: (UICollectionView *) коллекцияView numberOfItemsInSection: (NSInteger) раздел { return [recipeImages count]; } – Chenna

ответ

0

Эта линия, кажется, неправильно [recipeImages[indexPath.section] objectAtIndex:indexPath.row]

Если recipeImages является тип NSArray или NSMutableArray, вы должны использовать [recipeImages objectAtIndex:indexPath.row].

Пример:

if([recipeImages count] > indexPath.row) 
{ 
    recipeImageView.image = [UIImage imageNamed:[recipeImages objectAtIndex:indexPath.row]]; 
} 
else 
{ 
    NSLog(@"Unable to get the image name"); 
} 
+0

- [CustomCell setImage:]: непризнанный селектор, отправленный экземпляру, это ошибка, которую я получаю с помощью этого кода – Chenna

+0

вы добавили чек? if ([recipeImages count]> indexPath.row), см. обновленный ответ. –

+0

его отображение той же ошибки – Chenna

0

Проблема здесь вы пытаетесь лечить NSString как NSArray! Когда вы сказали, recipeImages[indexPath.section], он вернет вам тип строки. Теперь, если вы пытаетесь сделать, objectAtIndex по типу String, он сработает.

[recipeImages objectAtIndex:indexPath.row] должен решить вашу проблему.

Смежные вопросы