2016-04-14 29 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對單元格有效。