CollectionView navigationController?.pushViewController() 什么都不做,没有错误
CollectionView navigationController?.pushViewController() does nothing with no error
我创建了一个 CollectionView,我想打开一个 ViewController,其中包含具体的细节,具体取决于单击的行。(我没有使用故事板,这都是通过编程完成的)。
我查看了文档并尝试使用覆盖功能 didSelectItemAt
和 navigationController?.pushViewController()
但似乎没有任何反应。没有错误还是什么?查看我的代码:
(收藏ViewController)
(ViewController)
我也试过为 viewcontroller 提供布局,但没有成功。它显然接受了每一行的点击功能,因为它打印到日志中很好:
对于我在这里遗漏的任何帮助,我们将不胜感激。
首先,确保在你的TabBarController
中,控制器被初始化为navigationController
func viewDidLoad() {
let vc1 = UINavigationController(rootViewController: YourController())
viewControllers = [vc1, vc2]
}
在你把它放入viewControllers
数组之前,这样你就可以在vc1
中调用navigationController?.pushViewController()
另一件事:确保在推送前初始化 CollectionViewController
时提供流式布局,如下所示:
let layout = UICollectionViewFlowLayout()
let detailVC = PlaceDetailController(collectionViewLayout: layout)
detailVC.place = ... // Pass value here
navigationController?.pushViewController(detailVC, animated: true)
我创建了一个 CollectionView,我想打开一个 ViewController,其中包含具体的细节,具体取决于单击的行。(我没有使用故事板,这都是通过编程完成的)。
我查看了文档并尝试使用覆盖功能 didSelectItemAt
和 navigationController?.pushViewController()
但似乎没有任何反应。没有错误还是什么?查看我的代码:
(收藏ViewController)
(ViewController)
我也试过为 viewcontroller 提供布局,但没有成功。它显然接受了每一行的点击功能,因为它打印到日志中很好:
对于我在这里遗漏的任何帮助,我们将不胜感激。
首先,确保在你的TabBarController
中,控制器被初始化为navigationController
func viewDidLoad() {
let vc1 = UINavigationController(rootViewController: YourController())
viewControllers = [vc1, vc2]
}
在你把它放入viewControllers
数组之前,这样你就可以在vc1
navigationController?.pushViewController()
另一件事:确保在推送前初始化 CollectionViewController
时提供流式布局,如下所示:
let layout = UICollectionViewFlowLayout()
let detailVC = PlaceDetailController(collectionViewLayout: layout)
detailVC.place = ... // Pass value here
navigationController?.pushViewController(detailVC, animated: true)