views:

2194

answers:

7

I am developing a Window Based app for iPhone. I use Interface Builder to build Interface. I want to call a new screen with a Button Action. How can I call the screen with Button action ?

+1  A: 

By pushing the new controller onto the top of the stack of windows. For example:

EnterNameController *newEnterNameController = [[EnterNameController alloc] initWithNibName:@"EnterName" bundle:[NSBundle mainBundle]];
[[self navigationController] pushViewController:newEnterNameController animated:YES];
alamodey
Its working at Navigation based application. But Its not working at Window based application.
Nahid
As far as I know, you should always use a navigation controller even when you think you are opening screens (or windows) in a non-hierarchical way.
alamodey
+1  A: 

Apple has an extraordinary amount of sample code, and this question (as well as many others) could easily be solved by simply visiting Apple's iPhone dev site. iPhone Dev Site

August
A: 

If you are using a navigation controller, push it onto the navigation controller's stack, as alamodey suggested.

If you want it to be a modal controller (that is, slide up from the bottom and cover the previous controller's view, like the Bookmarks screen in Safari), present it as a modal view controller:

[self presentModalViewController:myNewController animated:YES];

When you want to bring the old controller back, dismiss the modal view controller. From inside the modal view controller:

[self.parentViewController dismissModalViewControllerAnimated:YES];

If you don't want to do either, just remove the current controller's view from the window and add the new controller's:

UIView * containingView = self.view.superview;
[self.view removeFromSuperview];
[containingView addSubview:myNewController.view];

If you go this route, you may want to look into +[UIView beginAnimations:context:], +[UIView setAnimationTransition:onView:], and +[UIView commitAnimations] (if I recall the method names correctly--check the documentation) to animate the transition. You should almost always animate any switch between screens in iPhone OS.

Brent Royal-Gordon
A: 

i have developed tabbar based appliction.as well as particular tabitem is pressed then view is open ok.in this view i add three button with the help of coding(means without using tools),then button is coming.i wrote this code inside DidViewLoad method.this is the code for button:

 UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
 [button setTitle:@"Create Tags" forState:UIControlStateNormal];
 button.frame = CGRectMake(100.0, 100.0, 100.0, 34.0);
 [self.view addSubview:button];
 [button addTarget:self action:@selector(createAction) forControlEvents:UIControlEventTouchUpInside];

but my problem is when i clicked on particular button then method is called but next view is not opened.this the code:

-(IBAction)createAction:(id)sender {WhoIsInAppDelegate *newEnterNameController = [[WhoIsInAppDelegate alloc] initWithNibName:@"Create Tags" bundle:[NSBundle mainBundle]]; [[self navigationController] pushViewController:newEnterNameController animated:YES];

} what is the wrong steps i doing please tell me.

Thanks in advanced.

A: 

@selector(createAction) needs to be @selector(createAction:)

colon indicates takes argument:sender

JDPearlman
A: 

can u please send me the function which is handling the change of the screen. I am New to this Objective C So i cant get u that where u have called the function to change the screen and the name of the function and the entire difenation

A: 

you just need to download sample applications from XCode help. Try Elements and UIcatalog. There are also other - type 'pushViewController' or 'addSubview' adn 'makeKeyAndVisible' in help and download samples

plusz