Here is the AppDelegate.swift implementation/ configuration:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var coordinator: MainCoordinator?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// Fabric.with([Crashlytics.self])
// FirebaseApp.configure()
let navigationController = UINavigationController()
coordinator = MainCoordinator(navigationController: navigationController)
coordinator?.start()
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = navigationController
self.window?.makeKeyAndVisible()
here is the MainCoordinator.swift
import Foundation
import UIKit
class MainCoordinator: Coordinator {
var subCoordinators = [Coordinator]()
var navigationController: UINavigationController
init(navigationController: UINavigationController) {
self.navigationController = navigationController
}
func start() {
let VC = SplashViewController.instantiate()
VC.coordinator = self
navigationController.pushViewController(VC, animated: false)
NSLog("view Started")
}
func goToMerchandizeEntranceView() {
let vc = MerchandizeEntranceViewController.instantiate()
vc.coordinator = self
navigationController.pushViewController(vc, animated: true)
}
func gotoMerchandizeRequestView() {
let vc = MerchandizeRequestStatusViewController.instantiate()
vc.coordinator = self
navigationController.pushViewController(vc, animated: true)
}
}
Here inside MainVC, in didselectItemAt IndexPath method of collection View should trigger to the next VC, however, VC is not triggered and displayed on secreen, " NsLog" prints the message though.. Can Anyone help me explain where i am wrong..?
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if collectionView == menuCollectionView {
switch indexPath.row {
case 0:
coordinator?.goToMerchandizeEntranceView()
NSLog("Receiving touch")
case 1:
coordinator?.gotoMerchandizeRequestView()
NSLog("Receiving touch")
default:
break
}
}
else {
NSLog("define action for story cell")
}
}
Update: Since you're using storyboard you should instantiate view controller from storyboard like this:
Seems your coordinator is not initialized in
MainVC. You should initialize your coordinator inviewDidLoad: