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

时间:2012-04-25 04:09:27

标签: ios uiviewcontroller navigation uibutton

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

7 个答案:

答案 0 :(得分:7)

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

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

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

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

答案 1 :(得分:6)

试试这个:

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

答案 2 :(得分:5)

Objective-C功能中使用此代码进行导航 -

DashboardViewController *dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DashboardView"];
[dvc setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:dvc animated:YES completion:nil];

答案 3 :(得分:4)

您可以使用任何方法 -

  
      
  1. pushViewController:animated: - 推送导航堆栈上的视图

  2.   
  3. presentModalViewController:nc animated: - 以模态方式显示视图。

  4.   

答案 4 :(得分:3)

YourSecondViewcontroller *temp = [[YourSecondViewcontroller alloc]initWithNibName:@"YourSecondViewcontroller" bundle:nil];
[self.navigationController pushViewController:temp animated:YES];

//或

[self presentModalViewController:temp animated:YES];

Visit this reference for tutorial and working demo code

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

答案 5 :(得分:1)

  

// SAViewController将是你的destiation视图

     

//在当前视图中导入SAViewController.h文件

SAViewController *admin = [[SAViewController alloc]initWithNibName:@"SAViewController" bundle:nil];
[self presentModalViewController:admin animated:YES];
[admin release];

答案 6 :(得分:0)

尝试以下代码:

- (IBAction)btnJoin:(id)sender {

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

}