gpt4 book ai didi

ios - 执行按钮操作后 UICollectionView rollToItemAtIndex

转载 作者:行者123 更新时间:2023-11-29 01:08:02 25 4
gpt4 key购买 nike

当弹出 currentViewController 时,我想将 mainViewController 中的 UICollectionView 滚动到 currentViewController 当前所在的项目的索引。我已经尝试在 currentViewController 的 viewWillDisappear 中实现它,但是当执行 back button 操作时没有任何反应。

   override func viewWillDisappear(animated : Bool) {
super.viewWillDisappear(animated)
if (self.isMovingFromParentViewController()){
let parent = parentViewController as! UINavigationController
let child = parent.childViewControllers[0] as! MainViewController
child.collectionView?.scrollToItemAtIndexPath(NSIndexPath(forItem: currentIndex, inSection: 0), atScrollPosition: .Top, animated: true)
}
}

最佳答案

因为您不是关闭而是弹出 View Controller ,这样的操作应该有效:

override func viewWillDisappear(animated: Bool) {
if let mainViewController = navigationController?.topViewController as? MainViewController {
mainViewController.collectionView?.scrollToItemAtIndexPath(NSIndexPath(forItem: currentIndex, inSection: 0), atScrollPosition: .CenteredVertically, animated: false)
}
super.viewWillDisappear(animated)
}

关于ios - 执行按钮操作后 UICollectionView rollToItemAtIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36118745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com