【发布时间】:2017-06-28 04:14:35
【问题描述】:
对于我的一生,我无法弄清楚为什么我不能让这个函数工作以响应indexPath 被选中。
当我在didSelectItemAtIndexPath 的行中添加断点时,它会中断,但是当我在viewscontroller 类中添加一个断点时,它不会中断。就好像信息正在发送,但无法到达目的地。我的控制台没有出现任何错误,而且我已经多次查看了所有内容。
这可能是一个 xcode 错误还是我错过了什么?
这里是我引用它所在的类的地方
var viewsController: ViewsController?
这是我的didSelectItemAtIndexPath
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
viewsController?.scrollToMenuIndex(indexPath.item)
print(indexPath.item)
}
这是函数本身
func scrollToMenuIndex(_ menuIndex: Int) {
let indexPath = IndexPath(item: menuIndex, section: 0)
collectionView?.scrollToItem(at: indexPath, at: UICollectionViewScrollPosition(), animated: true)
}
【问题讨论】:
-
一切正常,就好像我无法分离数据一样。 *请注意,这是在没有故事板的情况下以编程方式完成的。
-
如果 scrollToMenuIndex 属于同一类,那么 scrollToMenuIndex(indexPath.item) 就足够了!!
标签: ios swift uiscrollview uicollectionview