viewcontroller - Relationship among window, rootviewcontroller, childviewcontroller, navigationcontroller in iOS -


i haven't seen resource gives , simple explanations on relationship among window, rootviewcontroller, childviewcontroller, navigationcontroller , how piece in ios development. 1 knows how put in easy-to-understand way or online resource or book job in explaining it?

per documentation on uiwindow:

https://developer.apple.com/library/ios/documentation/uikit/reference/uiwindow_class/

a uiwindow object provides backdrop app’s user interface , provides important event-handling behaviors. windows not have visual appearance of own, crucial presentation of app’s views.

xcode typically provides application's main window, can add more if need to.

from documentation link can see uiwindow uiview

enter first view controller. providing main window, when start new project in xcode project template wires initial view controller, name implies controls view (uiview).

you call initial view controller rootviewcontroller if handle on uiwindow swap out current initial view controller's view other view controller view like.

that doesn't hard , fast rules things, if understand asking, rootviewcontroller initial view controller application. example, if using storyboards, xcode typically makes main.storyboard, see gray arrow pointing uiviewcontroller representation.

gray arrow

this pointing storyboards initial view controller. can verify attributes inspector. select view controller select attribute inspector:

initial view controller

so that's rootviewcontroller. childviewcontroller other view controller child of view controller.

i assume referring is:

addchildviewcontroller:  removefromparentviewcontroller  willmovetoparentviewcontroller:  didmovetoparentviewcontroller: 

you can read more these methods here: https://developer.apple.com/library/ios/documentation/uikit/reference/uiviewcontroller_class/

under implementing container view controller

the quick gist of is, view controller controls view. view's can have subviews. subviews can come other view controllers. methods outlined above pretty enable things viewwillappear, or viewwilldiappear called on child view controller automatically when methods invoked on parent view controller.

per docs:

by default, rotation , appearance callbacks automatically forwarded children. may optionally override shouldautomaticallyforwardrotationmethods , shouldautomaticallyforwardappearancemethods methods take control of behavior yourself.

a navigationcontroller other view controller. contains special behavior transitioning between views, other view controllers has view (uiview) manages. navigation controller initial view controller / rootviewcontroller other view controller can be, depends on trying do. example, simple app list view, can tap item , detail view constructed as:

1) initial view controller -> navigationcontroller

2) navigationcontroller's first viewcontroller (apple calls rootviewcontroller) tableviewcontroller.

3) selecting tablecell in tableview (tableviewcontroller manages tableview) transition detail view controller. navigation controller knows how sliding , forth drama.

that's pretty simplistic overview can search internet/youtube more full featured tutorials outlining same thing in more detail.

example: https://www.raywenderlich.com/113388/storyboards-tutorial-in-ios-9-part-1

it's worth time few of these bearings. yes, cost few hours of day. take heart, ever started doing ios development had go though same thing. =)


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -