ios - Please clear some confusions regarding UIViewController -


please clear confusions regarding uiviewcontroller

i found article abusing uiviewcontroller , here links link1 & link2

and summarised points

this author's (and apple’s) advice in nutshell:

  1. one (and one) view controller should responsible whole hierarchy (or screenful) of uiviews.
  2. mostly, should use 1 view controller per screen. rootviewcontroller of current uiwindow should uiviewcontroller visible view.
  3. each different screen should have different view controller i.e. 1 controller should not control more 1 screen.
  4. you should not nest custom uiviewcontrollers within view hierarchy.
  5. if more 1 uiviewcontroller hangs off application’s uiwindow, 1 of these messages changes in orientation. other(s) not these messages.
  6. nested uiviewcontrollers not guaranteed, or likely, receive messages changes in orientation or lifecycle messages such viewdidappear:, viewwillappear:, viewdiddisappear: , viewwilldisappear: though inherit uiviewcontroller. topmost uiviewcontroller these messages.

please clear point number 2 , 3 because when use uinavigationcontroller or uitabbarcontroller use multiple subclasses of uiviewcontroller. , ios device has 1 screen.....

this article abusing uiviewcontroller highlight apple suggestion

note: if want divide view hierarchy multiple subareas , manage each 1 separately, use generic controller objects (custom objects descending nsobject) instead of view controller objects manage each subarea. use single view controller object manage generic controller objects.

and in apple docs under heading of coordinating efforts between view controllers apple saying

few ios apps show single screenful of content. instead, show content when first launched , show , hide other content in response user actions. these transitions provide single unified user interface display lot of content, not @ once.....

my requirement not use container or modal or popover, want manual management, have 2 view controllers vc1 & vc2. vc1 root view controller want switch/transit/move vc2 should do?

  1. vc1 should subclass of uiviewcontroller , vc2 should subclass of nsobject manage particular view in vc1 hierarchy?(the show hide thing apple doc).

  2. vc2 can subclass of uiviewcontroller, remove vc1 root view , add vc2 root view?

or correct way?

container view controllers (like uinavigationcontroller) allow working around one-vc-per-screen rule. since ios 5, developers have been able , allowed write our own container controllers (which aren't different normal vcs). means writing non-vc controller objects less necessary used be.

in situation, want replace root view controller, option 2 makes more sense. use vcs can, , non-vc controller objects when can't. since you're replacing whole screen's content, switching uiwindow rootviewcontroller makes sense (edit: alternately, many devs use navigation controller present second view, because it's simple , convenient).


Comments