当前位置: 首页 - 编程技术 - 文章正文

简单跳转

xiaoqihv

创建继承于UIViewController的类 MyViewController MyViewController.m代码` 首先是viewDidLoad

UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btn.frame = CGRectMake(50, 100, 280, 30); [btn setTitle:@"第二个界面点击跳回" forState:UIControlStateNormal]; [btn addTarget:self action:@selector(tiao) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn];

接下来

-(void)tiao{ //使用导航控制器 跳转 pop 和push 左右跳转 其中参数animated:YES意思是跳转过程中是否用动画方式跳转// [self.navigationController popToRootViewControllerAnimated:YES]; //第二种跳转 是通过ViewController跳转 Animated:YES也是 是否动画方式跳转 present和dismiss 是一对 [self dismissViewControllerAnimated:YES completion:nil];}

AppDelegate.m代码 导入头文件#import “ViewController.h”

ViewController * vc = [[ViewController alloc]init]; self.window.rootViewController = [[UINavigationController alloc]initWithRootViewController:vc];

ViewController.m代码 导入头文件 #import “MyViewController.h” 首先viewDidLoad 里

UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btn.frame = CGRectMake(50, 100, 280, 30); [btn setTitle:@"第一个界面点击跳转" forState:UIControlStateNormal]; [btn addTarget:self action:@selector(tiao) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn];

接下来

-(void)tiao{ //使用导航控制器 跳转 pop 和push 左右跳转 其中参数animated:YES意思是跳转过程中是否用动画方式跳转 MyViewController * myVc = [[MyViewController alloc]init];// [self.navigationController pushViewController:myVc animated:YES]; //第二种跳转 是通过ViewController跳转 Animated:YES也是 是否动画方式跳转 present和dismiss 是一对 [self presentViewController:myVc animated:YES completion:nil];}
文章地址:https://wenmayi.cn/post/598.html