简体   繁体   中英

viewcontroller - how to get another root view controller / how to switch Views

I'm having problems understanding where the object viewController comes from. I have an existing app that provides a detail view, and I need to put a table view in front of that to be able to choose a specific detail view. The app starts with

self.window.rootViewController = self.viewController;

And I just don't get where (self.)viewController comes from. It's a property of my app delegate and it's in the .m -file of the app delegate:

@synthesize viewController=_viewController;

But I have no idea how the app knows, which viewController this is, because there seems to be no "assignment" or "creation" of the actual viewController object. And how would I move my tableView "in front" of the existing viewController ?

Thanks in advance!

In nib-based projects there is a key in Info.plist named NSMainNibFile , or “Main nib file base name”, that instructs UIApplication to load MainWindow.xib and hook it into the app.

So if you look in MainWindow.xib (or whatever xib is referenced in the Info.plist NSMainNibFile entry), you'll see a view controller. If you click on the view controller in the document outline (panel on the left of the xib view), you can change it's class in the Identity Inspector ( Command + Option + 3 , which pulls up the Identity Inspector in the right panel).

It's a little different with storyboards - the main nib key in Info.plist is now replaced with a main storyboard key, and the View Controllers now appear below each panel in the storyboard rather than in the document organizer - but it's basically the same idea.

The xib/storyboard file is compiled to code that allocs a UIViewController instance at startup and assigns the instance to the viewController variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM