I'm currently working on creating an iOS app from scratch without using the story board. Everything is working fine except one thing that I can't push the view controller from the cell within the rootViewController
, flow is down below, please mention without using storyboard, this project is something I wanna achieve without the storyboard:)
1, creating root view controller in 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,creating four cells as within the collection view controller file
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, i have another collection view which has dynamic number of the cells from my api model file , and those name above are with controller but they are collection view cell, i somehow named controller
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, registering another cell for this Conversation.swift, and so far everything is working the way i wanted
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)
}
What I want to achieve is that every time user tap on the ConversationCell
which is the ConversationController
I want to push the view controller using pushViewController
method in the UINavigationController
. I know this class doesn't have the super class of UICollectionViewController
or UIViewController
so what I tried was that because the HomeViewController
(at section 1) is UICollectionViewController
, I created the reference of HomeViewController
within the ConversationController
and made the method for pushing the viewController in HomeViewController
. I set the break point and it was running but the view didn't get pushed. I wan a bit confused what was going on. Any help or advice will be really helpful! Thank you:)