Please clear some confusions regarding UIViewController
I found this article Abusing UIViewController
and here are the links link1 & link2
and summarised points
This is author's (and Apple’s) advice In a nutshell:
- One (and only one) view controller should be responsible for a whole hierarchy (or screenful) of UIViews.
- Mostly, you should only use one view controller per screen. Essentially the
rootViewController
of the current UIWindow
should be the only UIViewController
with a visible view.
- Each different screen should have a different view controller i.e. one controller should not control more than one screen.
- You should NOT nest custom
UIViewControllers
within a view hierarchy.
- If more than one
UIViewController
hangs off the application’s UIWindow
, only one of these will get the messages for changes in orientation. The other(s) will NOT get these messages.
- Nested
UIViewControllers
are not guaranteed, or likely, to receive messages for changes in orientation or lifecycle messages such as viewDidAppear:
, viewWillAppear:
, viewDidDisappear:
and viewWillDisappear:
even though they inherit from UIViewController
. Only the topmost UIViewController
is certain to get these messages.
Please clear point number 2 and 3
because when we use UINavigationController
or UITabBarController
we use multiple subclasses of UIViewController
. And ios device has only one screen.....
This article Abusing UIViewController highlight apple suggestion
Note: If you want to divide a view hierarchy into multiple subareas
and manage each one separately, use generic controller objects (custom
objects descending from NSObject) instead of view controller objects
to manage each subarea. Then use a single view controller object to
manage the generic controller objects.
and in apple docs under heading of Coordinating Efforts Between View Controllers
apple saying
Few iOS apps show only a single screenful of content. Instead, they
show some content when first launched and then show and hide other
content in response to user actions. These transitions provide a
single unified user interface that display a lot of content, just not
all at once.....
My requirement is NOT to use any container or modal or popover, I want to do manual management, I have two view controllers VC1
& VC2
. VC1
is the root view controller now I want to switch/transit/move to VC2
what should I do?
VC1
should be the only subclass of UIViewController
and VC2
should be the subclass of NSObject
to manage a particular view in VC1
hierarchy?(the show hide thing by apple doc).
VC2
can also be the subclass of UIViewController
, I just remove VC1
from root view and add VC2
as root view?
or what is the correct way?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…