【发布时间】:2014-03-04 09:30:31
【问题描述】:
我在 uicollectionview 中有多个图像,例如网格视图。我想一次选择多个图像但无法使用此代码。请任何人提供有关此代码的想法。
我已经尝试过这段代码,但无法正常工作。
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath: (NSIndexPath *)indexPath
{
NSMutableArray *indexPaths = [NSMutableArray arrayWithObject:indexPath];
if (self.selectedItemIndexPath)
{
// if we had a previously selected cell
if ([indexPath compare:self.selectedItemIndexPath] == NSOrderedSame)
{
// if it's the same as the one we just tapped on, then we're unselecting it
self.selectedItemIndexPath = nil;
}
else
{
// if it's different, then add that old one to our list of cells to reload, and
// save the currently selected indexPath
[indexPaths addObject:self.selectedItemIndexPath];
self.selectedItemIndexPath = indexPath;
}
}
else
{
// else, we didn't have previously selected cell, so we only need to save this indexPath for future reference
self.selectedItemIndexPath = indexPath;
}
// and now only reload only the cells that need updating
[self.collectionView reloadItemsAtIndexPaths:indexPaths];
}
【问题讨论】:
-
此代码仅适用于单选,不适用于多选。
-
请任何人为这个问题提供解决方案。
-
我已经使用谷歌尝试了很长时间,请任何人为这个问题提供解决方案......
标签: uicollectionview uicollectionviewcell ios6.1