I am new to iOS Application development, please help me how can I go from one view controller
to another view controller
on button click?
Asked
Active
Viewed 4.9k times
12

Pavel Vladov
- 4,707
- 3
- 35
- 39

user1355217
- 131
- 1
- 1
- 3
-
On the IB builder, drag controll drag the button to the next view. (you CANT do this to go back, you have to use dismissmodalviewcontroller method) – Pochi Apr 25 '12 at 04:12
7 Answers
11
Follow the below step,let the button selector is
[button addTarget:select action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
and implement the selector as
-(void)buttonClick{
UIViewController *controler = [[UIViewController alloc] init];
[self.navigationController pushViewController:controler animated:YES];}
and also make sure viewController has NavigationController embedded within it and replace UIViewController with the Controller you wish to push.

sKhan
- 9,694
- 16
- 55
- 53
8
Use this code in your Objective-C
function for navigation -
DashboardViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DashboardView"];
[dvc setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:dvc animated:YES completion:nil];

sKhan
- 9,694
- 16
- 55
- 53

Mohammad Kamran Usmani
- 868
- 11
- 12
-
Code is indented by 4 spaces or 1 tab. You can also select the code and press Ctrl+K. – Artjom B. Apr 10 '15 at 15:37
7
Try this:
nextViewController *obj =[[nextViewController alloc]initWithNibName:@"nextViewController" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj release];

sKhan
- 9,694
- 16
- 55
- 53
4
YourSecondViewcontroller *temp = [[YourSecondViewcontroller alloc]initWithNibName:@"YourSecondViewcontroller" bundle:nil];
[self.navigationController pushViewController:temp animated:YES];
//or
[self presentModalViewController:temp animated:YES];
Visit this reference for tutorial and working demo code
Hope, this will help you..enjoy
2
//SAViewController will be your destiation view
// import SAViewController.h file in your current view
SAViewController *admin = [[SAViewController alloc]initWithNibName:@"SAViewController" bundle:nil];
[self presentModalViewController:admin animated:YES];
[admin release];
1
Try this code:
- (IBAction)btnJoin:(id)sender {
SecondViewController *ViewController2 = [self.storyboardinstantiateViewControllerWithIdentifier:@"SecondViewController"];
[self.navigationController pushViewController: ViewController2 animated:YES];
}

Cœur
- 37,241
- 25
- 195
- 267

Diptee Parmar
- 179
- 1
- 3