我有一个包含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];
}
我想在顶部添加新图片,但它位于底部
请帮助我,我是新目标c
答案 0 :(得分:0)
sessionStorage.setItem('newWorker', JSON.stringify(worker_record));
答案 1 :(得分:0)
检查我的答案@ satheesKumar Naidu
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);
// here i have make the changes**
if( [_imagearray[row] isKindOfClass:[UIImage class]]){
image = _imagearray[row]
}
else {
image = [UIImage imageNamed:_imagearray[row]];
}
cell.img.image = image;
cell.text.text=[_tittlearray objectAtIndex:indexPath.row];
return cell;
}
-(void) receivedArray:(NSNotification*)notification {
NSMutableArray* userInfo = notification.object;
if([userInfo count]>0) {
UIImage *image = [userInfo firstObject];
///[_imagearray addObject:[userInfo firstObject]]; use this it will diretly add to end of the last index
[_imagearray insertObject:[userInfo firstObject] atIndex:0]; // it will add to firstindex of the array value
NSLog(@"%@",_imagearray);
[self.collection reloadData];
// here do not want add the delegate itself.
NSLog(@"%@",_imagearray);
} // it will check the nil object and to prevent the crash
}