Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS导航控制器寻根swift_Ios_Swift_Navigationcontroller - Fatal编程技术网

iOS导航控制器寻根swift

iOS导航控制器寻根swift,ios,swift,navigationcontroller,Ios,Swift,Navigationcontroller,我目前正致力于在不使用故事板的情况下从头开始创建iOS应用程序。除了一件事我不能从rootViewController中的单元格中推送视图控制器外,一切都很正常,下面的流程是向下的,请注意不要使用故事板,这个项目是我想要在没有故事板的情况下实现的:) 1,在AppDelegate.swift中创建根视图控制器 let layout = UICollectionViewFlowLayout() let homeViewController = HomeViewController(collecti

我目前正致力于在不使用故事板的情况下从头开始创建iOS应用程序。除了一件事我不能从
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的方法中设置了断点。它们都运行正常,问题是它没有推动视图。谢谢你的建议!