iOS导航控制器寻根swift
我目前正致力于在不使用故事板的情况下从头开始创建iOS应用程序。除了一件事我不能从iOS导航控制器寻根swift,ios,swift,navigationcontroller,Ios,Swift,Navigationcontroller,我目前正致力于在不使用故事板的情况下从头开始创建iOS应用程序。除了一件事我不能从rootViewController中的单元格中推送视图控制器外,一切都很正常,下面的流程是向下的,请注意不要使用故事板,这个项目是我想要在没有故事板的情况下实现的:) 1,在AppDelegate.swift中创建根视图控制器 let layout = UICollectionViewFlowLayout() let homeViewController = HomeViewController(collecti
rootViewController
中的单元格中推送视图控制器外,一切都很正常,下面的流程是向下的,请注意不要使用故事板,这个项目是我想要在没有故事板的情况下实现的:)1,在AppDelegate.swift中创建根视图控制器
let layout = UICollectionViewFlowLayout()
let homeViewController = HomeViewController(collectionViewLayout: layout)
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = UINavigationController(rootViewController: homeViewController)
return true
2、在集合视图控制器文件中创建四个单元格collectionView?.register(HomeController.self, forCellWithReuseIdentifier: sections[0])
collectionView?.register(PortfolioController.self, forCellWithReuseIdentifier: sections[1])
collectionView?.register(ConversationController.self, forCellWithReuseIdentifier: sections[2])
collectionView?.register(ProfileController.self, forCellWithReuseIdentifier: sections[3])
3,我有另一个集合视图,它有来自我的api模型文件的动态单元格数,上面的那个些名称是带有控制器的,但它们是集合视图单元格,我以某种方式命名为控制器
class ConversationController: BaseCell, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UICollectionViewDelegate {
lazy var collectionview: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
cv.dataSource = self
cv.delegate = self
cv.backgroundColor = UIColor.white
return cv
}()
4、为这次对话注册另一个手机。swift,到目前为止,一切都按照我想要的方式进行override func setUpViews() {
super.setUpViews()
fetchMessage()
addSubview(collectionview)
addConstraintsWithFormat(format: "H:|[v0]|", views: collectionview)
addConstraintsWithFormat(format: "V:|[v0]|", views: collectionview)
collectionview.register(ConversationView.self, forCellWithReuseIdentifier: cellId)
}
我想要实现的是,每次用户点击
ConversationCell
时,这是ConversationController
,我想要使用UINavigationController
中的pushViewController
方法推送视图控制器。我知道这个类没有超级类UICollectionViewController
或UIViewController
,所以我尝试的是因为HomeViewController
(在第1节)是UICollectionViewController
,我在ConversationController
中创建了HomeViewController
的引用,并制定了在HomeViewController
中推送viewController的方法。我设置了断点,它正在运行,但视图没有被推。我有点搞不清楚发生了什么事。任何帮助或建议都会非常有用!谢谢:)这只是一件愚蠢的事情,因为我很多时候都错过了。只需检查导航控制器是否已初始化,或者它是否为nil,您正在尝试推送。您是否可以在didSelectCellAtIndexPath
中推送视图?否则,您需要创建一个协议,并将集合视图控制器设置为cells委托。当点击单元格时,它可以触发委托方法来通知视图控制器I在didSelectItemAtIndexPath中添加了调用HomeViewController的方法self.navigationController.pushViewController(目标)的方法,因为此对话控制器不是viewController,所以无法从视图右侧推送视图控制器?我还在didSelectItemAtIndexPath和HomeViewController的方法中设置了断点。它们都运行正常,问题是它没有推动视图。谢谢你的建议!这只是一个愚蠢的检查,因为我错过了很多时间。只需检查导航控制器是否已初始化,或者它是否为nil,您正在尝试推送。您是否可以在didSelectCellAtIndexPath
中推送视图?否则,您需要创建一个协议,并将集合视图控制器设置为cells委托。当点击单元格时,它可以触发委托方法来通知视图控制器I在didSelectItemAtIndexPath中添加了调用HomeViewController的方法self.navigationController.pushViewController(目标)的方法,因为此对话控制器不是viewController,所以无法从视图右侧推送视图控制器?我还在didSelectItemAtIndexPath和HomeViewController的方法中设置了断点。它们都运行正常,问题是它没有推动视图。谢谢你的建议!