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



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

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

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

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

并确保 viewController 中嵌入了导航控制器,并将 UIViewController 替换为您要推送的控制器。

Objective-C 函数中使用此代码进行导航 -

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

试试这个:

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

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

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

  2. 当前模式视图控制器:nc 动画: - 以模式呈现视图。

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

希望,这会对你有所帮助。享受

/

/SAViewController 将是你的命运视图

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

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

试试这段代码:

- (IBAction)btnJoin:(id)sender {
   SecondViewController *ViewController2 = [self.storyboardinstantiateViewControllerWithIdentifier:@"SecondViewController"];
   [self.navigationController pushViewController: ViewController2 animated:YES];
}

相关内容

  • 没有找到相关文章

最新更新