iPhone ViewController loading as UIModal and UINavigation - how to differentiate
Maybe someone can drop me a pointer. I've got a UIViewController
that is being served up as both a UIModalViewController
and pushed onto the view stack via a UINavigationController
- depending on where the user launches the view from within the app. I want to load two different HTTP Requests based on how the user loads开发者_如何学C the view, so I need a conditional in viewDidLoad
to determine where the view came from in order to call the correct request. Any ideas?
You're halfway there already. Rather than your UIViewController being aware of how it was launched, I suggest that you have the various places in your code which create the view controller configure it at or after creation with some information regarding its desired behaviour -- for example, configuring which URL it should download. Then, in viewDidLoad or elsewhere in your view controller, you can just do the correct thing based on how your UIViewController was configured.
So, as a solid example, have an init method for your VC take as a parameter the desired URL (or have it settable as a property). Then later on in viewDidLoad (or wherever you like) your VC can do the correct thing without being 'polluted' with details it shouldn't really care about (such as how it was pushed onto the UI etc.)
精彩评论