How would one change the view on the screen programmatically in an iPhone app?
I've been able to create navigation view's and programmatically push/pop them to produce this behaviour, but if I wanted to simply change the current view (not using a UINavigation controller object), what is the neatest way to achieve this?
A simple example, imagine an application with a single button, when pressed will display a new view, or possibly one of multiple views depending on some internal state variable.
I have yet to see any examples that attempt to do this, and I don't seem to understand enough about the relationships and initialisation procedure between UIViewController/UIView objects to achieve this programmatically.
I use presentModalViewController:animated:
to bring up a settings view from my main window's UIViewController
and then when the user presses "done" in the settings view I call dismissModalViewControllerAnimated:
from the settings view (reaching back to the parent view) like this:
[[self parentViewController] dismissModalViewControllerAnimated:YES];
You'll want to explore -[UIView addSubview:]
and -[UIView removeFromSuperview]
. Your base window is a UIView
(descendant), so you can add and remove views to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With