2016-04-14 57 views
1

我正在调用此方法,nextCellIndexPath是一个大于当前单元格的indexPath,但indexPath未正确递增。如何增加UICollectionView的NSIndexPath

这里是cellForItemAtIndexPath:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("collectionViewCell", forIndexPath: indexPath) as! ImageCollectionViewCell 
    cell.nextCellIndexPath = indexPath.indexPathByAddingIndex(1) 
    return cell 
} 

当我试图滚动到下一个indexPath,看来该indexPath不会增加。

那么如何正确获取下一个indexPath呢?

+0

它看起来就像你分配'nextCell'是一个'NSIndexPath'实例,而不是一个细胞,是正确的? – Dash

+0

正确。我可能应该重命名它。 –

+0

当您调用滚动时,该项目是否已在屏幕上可见?我认为只有当物品不完全可见时才会滚动。 – Dash

回答

3

此代码:indexPath.indexPathByAddingIndex(1)没有做你期待的。这将为indexPath添加一个索引,而不是移动到下一行。

尝试创建一个新的NSIndexPath使用这样的事情

let nextIndexPath:NSIndexPath = NSIndexPath(forRow: indexPath.row + 1, inSection: indexPath.section) 
1

此代码在出队可重用概念方面看起来很危险。您将indexPath对象分配给可重用单元的属性,但您无法确定,当您尝试从rightBumperTapped方法访问它时,此indexPath对单元格有效。