У меня есть массив из 15 элементов, и я добавляю их в коллекцию вида клеткуКак реверс ячейки просмотра коллекции
_imagearray=[@[@"bootimages",@"fall-photography-in-hocking-hills", @"gift",@"hillimages",@"Mercedes-classe-S-W116_large_dettaglio_articolo",@"prinimages",@"resplendent",@"tnb4",@"Tomato-plant",@"Vole",@"waterimages",@"fall-photography-in-hocking-hills", @"gift",@"hillimages",@"Mercedes-classe-S-W116_large_dettaglio_articolo"]mutableCopy];
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
//[self.collection reloadData];
homeceeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
UIImage *image;
NSInteger row = [indexPath row];
NSLog(@"indexpath = %ld", (long)row);
image = [UIImage imageNamed:_imagearray[row]];
cell.img.image = image;
cell.text.text=[_tittlearray objectAtIndex:indexPath.row];
return cell;
}
и я в следующем контроллере представления я беру изображение с помощью камеры и сохранения в в массив и я передаю массив обратно в первый контроллер представления с использованием NSNotificationCenter
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedArray:) name:@"ShareArray" object:nil];
-(void) receivedArray:(NSNotification*)notification
{
NSMutableArray* userInfo = notification.object;
UIImage *image = [userInfo firstObject];
[_imagearray addObject:[userInfo firstObject]];
NSLog(@"%@",_imagearray);
[self.collection reloadData];
_collection.delegate=self;
_collection.dataSource=self;
NSLog(@"%@",_imagearray);
}
I am Reloading the collection view cell and the new image doesn't have name
if (indexPath.row == 15) {
image= _imagearray[row];
//[_imagearray insertObject:image atIndex:0];
}else {
image = [UIImage imageNamed:_imagearray[row]];
}
cell.img.image = image;
cell.text.text=[_tittlearray objectAtIndex:indexPath.row];
}
Я хочу, чтобы добавить новое изображение на вершине, но он находится в нижней
, пожалуйста, помогите мне я новичок в Objective C
просто добавить изображение в месте в «0» индекса и перезагрузите CollectionView [_imagearray insertObject: @ "imagename" atIndex: 0]; –
использование [_imagearray insertObject: [userInfo firstObject] atIndex: 0]; in receivedArray метод –
проверить мой ответ @satheeskumar naidu. если у вас есть сомнения, спросите меня –