2
votes

Despite the title of this question, I am well aware that UIViewControllers cannot be placed inside UIViews.

Per Apple's documentation, UIViewControllers control the full screen in iPhone apps. However, on the iPad, they can also be used to control the contents of popover and split views as well as the full screen.

In my design, a number of very complex views, each with its own UIViewController, will be swapped in and out in an iPhone-sized rectangle in the center of the screen. This would be trivial if I were to use a popover, but I don't want the arrow or the black border that comes with it.

I have thought of two possibilities for dealing with this situation:

  • Place the view controllers in a new UIWindow
  • Use controller classes which do not inherit from UIViewController for those views

Which of these methods is least likely to cause future headaches? Please let me know if there is a better way to do this that I have not thought of.

3

3 Answers

2
votes

I use controller classes that do not inherit from UIViewController. The inability to nest actual view controllers arbitrarily in your UI hierarchy is an unfortunate unfairness in the SDK, but I have found that even having faux-controllers of real complexity are reasonable to manage. I just plumb through the critical messages from the real root controller as necessary, and structure the code in a similar way as if it were a real view controller. This is basically Apple's recommendation, also. (Can't find the doc reference at the moment.)

If you have LOTS of sub-screen manageable views like this, you could probably build a nicely flexible MyViewController class that inherits from NSObject, and then a MyBaseViewController that inherits from UIViewController that knows how to spawn MyViewControllers and sets up all the messaging appropriately for you. (I haven't needed this level of abstraction yet myself.)

Using sub-screen-sized UIWindows is not a standard solution, and I'd be wary of it. Similarly, don't try to just bash ahead and use UIViewControllers anyways. You'll find that if you do so, they'll behave sometimes and misbehave sometimes and you'll waste a lot of time sorting out that fragile interaction.

1
votes

From personal experience I suggest the following:

For each "logical unit", or module, for instance a message list, message composer view and a folder list; create its own UIViewController and .nib file.

Try to keep the code of each module separate, so that it does not need to know much or any details about other modules by providing clear interfaces between them.

Have one "main controller" which keeps track of all instances of all views and how/when they are displayed.

For me it saved a lot of headache, especially if you want to use most of the same codebase for iPhone AND iPad apps.

Overview

0
votes

You can put a UINavigationController inside a popover