Multiple View Controllers for a single View on the iPhone
Think an iPhone-based email client. You have three 'states' with the same UI: New Message, Reply and Forward (ignoring any others).
I'd li开发者_JAVA百科ke to have one view and have different View Controllers interfacing with the view. Given that the view is built in Interface Builder (with quite a few IBOutlets and IBActions), what is the best way to do this?
I suggest what you are saying doesn't really make sense.
The same view controller (ie, "your application" essentially) would just change between the three needs.
Also - it seems unlikely the three views would be exactly the same, hence make three different views/controllers.
(It's completely normal that you have many "similar" views -- which are indeed just separate views, but they happen to be graphically similar.)
Also - it's very likely you could have one overall view(/controller), and simply sitting inside it would be the specific writing/reading/whatever view(/controller).
I hope it helps!
One way to do it might be to create one view controller which contains all the Interface Builder connections, and then subclass that view controller multiple times. In code, you could instantiate the subclasses all using the same nib with -initWithNibName:bundle:.
Alternatively, your view controller could have kind of "mode" value, which determines its behavior based on the state it should be in. The view controller presenting it would then be responsible for setting it up appropriately.
精彩评论