【发布时间】:2016-10-02 10:06:12
【问题描述】:
更新到 Xcode8 后,以下代码不再工作
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 的值总是 nil。 有什么想法吗?
【问题讨论】:
-
检查调试器中的层次结构,从collectionView开始,向上运行superview列表。想清楚后,把答案贴在这里。
-
我已经检查了层次结构和超级视图列表。一切似乎都还好。我可以在调试器中看到 indexPath 有一个值,但是在“let indexPath = table.indexPath(for:cell)”行之后,该值变为 nil。
标签: uitableview uicollectionview xcode8 indexpath