下午所有,
几个星期前,我查看了UICollectionView,以及它们如何运作。对于我正处于开发初期阶段的项目,我觉得他们是最好的选择。
现在我已经能够建立视图,从我在viewDidLoad方法上建立的字符串的静态列表中填充它,用于获取图像的名称。但是,我现在使用MutableArray存储UIImage本身,但不幸的是我似乎无法填充表格。
[super viewDidLoad];
imageArray = [[NSMutableArray alloc] init];
[imageArray addObject:[UIImage imageNamed:@"BlankBloop.png"]];
既然我正在使用图像本身而不是简单的字符串,我必须编辑cellForItemAtIndexPath方法来抓取对象本身
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView *cellImageView = (UIImageView *) [cell viewWithTag:100];
cellImageView.image = [imageArray objectAtIndex:indexPath.row];
return cell; }
Cell正确标记为“Cell”,并且标记为100的UIImageView,但如上所述,我似乎无法填充视图。
这很可能是我的一个小错误,因为我必须从以前的方法转移,如果是这样,那么它就是学习过程的一部分。
无论哪种方式,如果有人能够了解情况,我会非常感激。提前致谢,