How to navigate from one view controller to anothe

2019-02-12 16:13发布

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?

7条回答
我只想做你的唯一
2楼-- · 2019-02-12 16:30

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.

查看更多
小情绪 Triste *
3楼-- · 2019-02-12 16:35

Try this code:

- (IBAction)btnJoin:(id)sender {

   SecondViewController *ViewController2 = [self.storyboardinstantiateViewControllerWithIdentifier:@"SecondViewController"];
   [self.navigationController pushViewController: ViewController2 animated:YES];

}
查看更多
Rolldiameter
4楼-- · 2019-02-12 16:36

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];
查看更多
孤傲高冷的网名
5楼-- · 2019-02-12 16:36
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

查看更多
贪生不怕死
6楼-- · 2019-02-12 16:39

You can use any of approach -

  1. pushViewController: animated: - To Push the view on navigation stack

  2. presentModalViewController:nc animated: - To present the view modally.

查看更多
放我归山
7楼-- · 2019-02-12 16:40

Try this:

nextViewController *obj =[[nextViewController alloc]initWithNibName:@"nextViewController" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj release];
查看更多
登录 后发表回答