我不知道为什么这不起作用.indexOfIcon是正确的,部分是正确的(用NSLog检查)如果我选择一个一切都是正确的.但这条线没有做什么......为什么?如果选中它应该有一个蓝色边框.这在"手动"但不是代码的情况下工作得很好.
- (void)viewWillAppear:(BOOL)animated { NSUInteger indexOfIcon; if(self.mainCategory.icon){ indexOfIcon = [self.icons indexOfObject: self.mainCategory.icon]; } else { indexOfIcon = 0; } [self.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:indexOfIcon inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionBottom]; }
zeiteisen.. 9
加
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath]; cell.selected = YES;
并将选择单元格.
该命令[self.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForRow:indexOfIcon inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionBottom];
告诉collectionView,单元格处于选中状态,但不设置单元格的状态.