我在将数据从详细 View Controller 传递到主视图 Controller 时遇到问题。感兴趣部分的层次结构是
TabBarController -> Profile View Controller --segue--> Navigation Controller -> Detail View Controller
详细 View Controller 包含图像的 UICollectionView,每个图像都有一个点击手势识别器。我想做的是点击其中一张图像,将 indexPath.row 传递给 ProfileViewController 并以编程方式返回。
当我转到详细信息 View Controller 时,那里已经有一个“后退”按钮,因此想法是:如果用户按下“返回”按钮,则不会发生任何事情。如果用户按下图像,后退按钮会自行触发,并且配置文件中的图像会发生变化。
到目前为止,我可以点击图像,传递indexPath.row,但我无法返回到之前的 View Controller 。
我尝试过 navigationController?.popViewControllerAnimated(true)
和 navigationController?.popToRootViewControllerAnimated(true)
但它们都不起作用(我将它们放入手势的点击功能中,导航 Controller 没有任何反应,点击功能工作正常)
当我打印以下内容时,我得到 1 navigationController.viewControllers.count
我唯一能做的就是 dismissViewControllerAnimated
但是它会从 TabBarController 转到之前的另一个 View 。
最佳答案
更新
我发现了,它与编程无关,正确的答案是使用
navigationController?.popViewControllerAnimated(true)
但是我的 View 层次结构是错误的
TabBarController -> Navigation Controller -> Profile View Controller --segue-> Detail View Controller
现在一切正常了
关于ios - 如何以编程方式从详细 View Controller 返回到主视图 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34853422/