【发布时间】:2013-05-31 16:00:12
【问题描述】:
我没有经常使用 UICollectionView,所以这可能是不可能的,但问一下也无妨 :)
每个单元格都设置为不同的颜色。
我想要做的是点击一个单元格并推送到另一个 UIViewController,该控制器将包含一个与所选颜色相同的 UIImageView。
现在我可以更改第二个 UIViewController 视图的颜色,但不能更改其中的 UIImageView。
这是我的一些代码:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
ImageViewController * imageVC = [[ImageViewController alloc] initWithNibName:@"ImageViewController" bundle:nil];
self.flatColor = [self colorForRow:indexPath.row];
[self.navigationController pushViewController:imageVC animated:YES];
imageVC.colorImageView.backgroundColor = _flatColor;
}
- (UIColor *)colorForRow:(NSInteger)row
{
UIColor *color;
switch (row)
{
case 0:
color = [UIColor redColor];
break;
case 2:
color = [UIColor greenColor];
break;
case 4:
color = [UIColor blueColor];
break;
default:
color = [UIColor yellowColor];
break;
}
return color;
}
编辑:
解决了这个问题。
我不得不重新排列一些代码。新的viewController需要先完全加载,然后修改UIImageView的backgroundColor
【问题讨论】:
标签: objective-c uiimageview uicollectionview uicolor uicollectionviewcell