我第一次使用 UICollectionView。我正在尝试获取每个单元格的“行”值 - 用作单元格文本字段的标识符/标签。当调用 cellForItemAtIndexPath 时,似乎 [indexPath row]; 返回 nil。当行为零时,如何获取单元格索引(或用作标识符的其他内容)?
注意 使用 iOS7,如果这有什么不同......
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
// Returns nil
NSLog("Row: %d", indexPath.row);
}
有什么想法/提示吗?
最佳答案
您不在 Collection View 中使用行的概念。您需要使用 NSIndexPath 中的此方法:
+ (NSIndexPath *)indexPathForItem:(NSInteger)item inSection:(NSInteger)section;
请注意 NSIndexPath 的 row 属性是在 UITableView.h 上声明的,而 item 属性在 UICollectionView.h
关于ios - UICollectionView cellForItemAtIndexPath indexPath 行为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18153076/