简体   繁体   中英

How to navigate from one view controller to another view controller on button click?

我是iOS应用程序开发的新手,请帮助我如何在按钮单击时从一个view controller转到另一个view controller

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.

Try this:

nextViewController *obj =[[nextViewController alloc]initWithNibName:@"nextViewController" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj release];

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];

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.

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

//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];

Try this code:

- (IBAction)btnJoin:(id)sender {

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM