I'm new at developing iPhone applications. Application i want to write now is very simple.
I want to have to "screens". For doing this i've created to UIViewController
subcl开发者_Python百科asses for both of them. The first one have a button - and when it's pressed i want to change the screen to the second. For doing this i want to send a message to shared AppDelegate
object and to change the view in my window.
Maybe it's important: The first screen is used for entering ip address of the server i want to connect to. So this screen will appear only once in the application
Am i on the right way ?
The APIs you are looking for are both found in UIViewcontroller:
- [UIViewController presentModalViewController:animated:];
and
- [UIViewController dismissModalViewController:animated:];
It will be better if ull push and pop the viewControllers to the navigation.
code example:
-(IBAction) CallNumberClicked
{
static DialNumberViewController *viewController=nil;
if(viewController==nil)
viewController=[[DialNumberViewController alloc] initWithNibName:@"DialNumberViewController" bundle:nil];
[self.navigationController pushViewController:viewController animated:YES];
}
To go along with what the others have already added. You should take a look(if you haven't already) at Apple's 'View Controller Programming Guide'. It will provide some good insight into managing the views, and provide examples of the different methods for doing so(Pushing,Modal,etc).
EDIT
Since it sounds like you want to show one view at a time(no stack, no modal) then you should really look at a UITabBarController to help organize your View Controllers. This will allow you to switch from one to the other easily. Here is some detail on how to set one up, you will need to scroll down to the 'Tab Bar' section. Hope that helps!
The way I do this is with protocols and callbacks. The current ViewController calls back to an original one and the original one releases the "current" one.
精彩评论