【发布时间】:2014-06-19 04:07:19
【问题描述】:
我是IOS开发新手,我尝试使用UIcollectionView来展示照片而不使用storyboard。
我创建了一个 xib file 调用 AITFileCell_grid.xib ,并添加了一个 Collection View Cell。
我还创建另一个xib file 并添加Collection View 以加载Collection View Cell。
我想选择多个文件并通过delete button删除它们。
但是当我通过以下代码单击delete button 时无法获取单元格。
if(self.collectionView.indexPathsForSelectedItems > 0){
NSLog(@"indexPathsForSelectedItems...count.%@..@@@" , self.collectionView.indexPathsForSelectedItems);
for(NSIndexPath *indexPath in self.collectionView.indexPathsForSelectedItems){
// [self.collectionView deselectItemAtIndexPath:indexPath animated:NO];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", directory, [fileList objectAtIndex:indexPath.row]];
[[NSFileManager defaultManager] removeItemAtPath:filePath error:nil] ;
AITFileCell_grid *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"AITFileCell_grid" forIndexPath:indexPath];
}
}
但卖出似乎不正确...
如何获取collectionView中的selected cell?
【问题讨论】:
-
先给
delete.tag =indexpath.item这样的标签,然后在选择时维护数组。之后,当您想要删除而不是使用 for 循环时,您可以从数组中删除数据,只需[collectionview reloaddata]。
标签: ios objective-c uicollectionview uicollectionviewcell