2016-10-02 24 views
0

的更新Xcode8後,下面的代碼不工作了特定的UITableViewCell的indexPath始終是零

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 


    let cell = collectionView.superview!.superview as! UITableViewCell 
    let table = cell.superview!.superview as! UITableView 
    let indexPath = table.indexPath(for: cell) 

現在indexPath的值始終爲零。 任何想法?

+0

更換的最後一行檢查調試器中的層次,首先是的CollectionView,跑起來的上海華表解決了這個問題。解決後,在這裏發佈答案。 – danh

+0

我已檢查層次結構和超級檢視列表。一切似乎都沒問題。我可以在調試器中看到indexPath有一個值,但在「let indexPath = table.indexPath(for:cell)」行後面,值更改爲nil。 –

回答

0

我用

let indexPath = table.indexPathForRow(at: cell.center) 
+0

任何人都可以解釋,爲什麼這種方式工作,而另一個不是? –