【发布时间】:2014-06-12 10:35:51
【问题描述】:
我正在使用集合视图在用户选择的滑块中显示多个图像,但主要问题是集合视图仅在页面加载时加载。而我的包含图像的数组是在页面加载后创建的。这就是为什么不加载图像的原因,因为一旦加载页面就不会加载集合视图。 我对收藏视图了解不多所以请指导我... 我的代码如下:-
- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
_imageList= [NSMutableArray arrayWithCapacity:[info count]];
for (NSDictionary *dict in info)
{
UIImage *image = [dict objectForKey:UIImagePickerControllerOriginalImage];
[_imageList addObject:image];
}
self.chosenImages = _imageList;
}
- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection: (NSInteger)section{
int numberOfItem = 0;
if (_imageList)
{
numberOfItem = _imageList.count;
}
return numberOfItem;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"ImageCell";
[collectionView registerClass:[ImageCell class] forCellWithReuseIdentifier:cellIdentifier];
ImageCell *cell = (ImageCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier
forIndexPath:indexPath];
// if(LOGS_ON) NSLog(@"cell = %@",cell);
if (!cell) {
// if(LOGS_ON) NSLog(@"Creating cell");
cell = [[ImageCell alloc] initWithFrame:CGRectMake(0, 0, 85, 110)];
cell.delegate = self;
}
cell.delegate = self;
cell.indexPath = indexPath;
// if(LOGS_ON) NSLog(@"image = %@", cell.imageView);
cell.cellImage.image = [UIImage imageNamed:[_imageList objectAtIndex:indexPath.row]];
return cell;
}
-(void) imageCell:(ImageCell *)imageCell buttonClickedAtIndexPath:(NSIndexPath *)indexPath{
[_imageList removeObjectAtIndex:indexPath.row];
[_imageGrid reloadData];
}
集合视图中的_imageList 项目数未加载
【问题讨论】:
标签: ios7 uicollectionview