This code illustrates what I am asking:
For a simple app having 2 screens, the rootViewController
and a TableViewController
, the rootVC
will be at index [0] in navigationController
, the next views will increments the index by 1
import UIKit
import CoreData
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let navController = self.window?.rootViewController as! UINavigationController
let firstViewController = navController.viewControllers[0] as! firstViewController
firstViewController.managedObjectContext = self.managedObjectContext
return true
}
Now I am trying to pass managedObjectContext
from appDelegate
to the ViewControllers behind the rootViewController
:
The center view is rootViewController
, I want to pass managedObjectContext
to the screens next, above and below it.
I have tried passing it from appDelegate
to rootViewController
, then passing from rootViewController
to the next views but it does not work.
Anyone please tell me how to know the index numbers of the views following the same view? Thank you!