如何在按钮单击时从一个视图控制器导航到另一个视图控制器?

use*_*217 10 navigation uibutton uiviewcontroller ios

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

sil*_*eep 9

按照以下步骤,让按钮选择器

[button addTarget:select action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside]; 并将选择器实现为

-(void)buttonClick{
UIViewController *controler = [[UIViewController alloc] init];
[self.navigationController pushViewController:controler animated:YES];}
Run Code Online (Sandbox Code Playgroud)

并确保viewController中嵌入了NavigationController,并将UIViewController替换为您想要推送的Controller.


小智 7

试试这个:

nextViewController *obj =[[nextViewController alloc]initWithNibName:@"nextViewController" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj release];
Run Code Online (Sandbox Code Playgroud)


小智 6

在您Objective-C的导航功能中使用此代码-

DashboardViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DashboardView"];
[dvc setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:dvc animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)


ris*_*shi 5

您可以使用任何一种方法-

  1. pushViewController:动画:-在导航堆栈上推送视图

  2. presentModalViewController:nc动画:-以模态显示视图。


Nit*_*Nit 4

YourSecondViewcontroller *temp = [[YourSecondViewcontroller alloc]initWithNibName:@"YourSecondViewcontroller" bundle:nil];
[self.navigationController pushViewController:temp animated:YES];
Run Code Online (Sandbox Code Playgroud)

//或者

[self presentModalViewController:temp animated:YES];
Run Code Online (Sandbox Code Playgroud)

Visit this reference for tutorial and working demo code

希望,这会帮助你..享受