【发布时间】:2015-03-15 22:31:05
【问题描述】:
我正在使用UICollectionView 使用PSTCollectionView
图书馆。我必须创建一个用户可以选择和取消选择的网格
通过点击UICollectionViewCell 获取图像。我必须显示复选框
如果选择了单元格,则为图像。如果单元格是 uncheckedBox 图像
取消选择。我可以选择cell 并显示复选框图像。并且
也可以取消选择。但是当我选择下一个cell时,前一个被取消选中
cell 也被选中并显示复选框图像。这是我在UICollectionViewCell子类中声明的方法
-(void)applySelection{
if(_isSelected){
_isSelected=FALSE;
self.contentView.backgroundColor=[UIColor whiteColor];
self.selectImage.image=[UIImage imageNamed:@"unchecked_edit_image.png"];
}else{
_isSelected=TRUE;
self.contentView.backgroundColor=[UIColor whiteColor];
self.selectImage.image=[UIImage imageNamed:@"checked_edit_image.png"];
}
}
这是我的didSelectItemAtIndexPath 代码和
didDeselectItemAtIndexPath
- (void)collectionView:(PSTCollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"didSelect method called");
FriendImageCell *cell = (FriendImageCell*)[imageGrid cellForItemAtIndexPath:indexPath];
[selectedImages addObject:[[list objectAtIndex:indexPath.item] objectForKey:@"thumbnail_path_150_150"]];
[cell applySelection];
}
- (void)collectionView:(PSTCollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"did deselect called");
FriendImageCell *cell = (FriendImageCell*)[imageGrid cellForItemAtIndexPath:indexPath];
[selectedImages removeObjectAtIndex:indexPath.item];
[cell setSelected:NO];
[cell applySelection];
}
谁能让我理解我的代码有什么问题?制作 如果我做错了什么,我会纠正。尝试了很多答案 堆栈溢出但没有任何效果。任何帮助,将不胜感激。 提前致谢。
【问题讨论】:
-
你的
indexPath.item是什么?我在NSIndexPath reference 中找不到它。 -
在
UICollectionView中,单元格被视为项目。
标签: ios objective-c uicollectionview uicollectionviewcell pstcollectionview