视图间的两种跳转方法

视图之间一共有两种跳转方法

第一种方法

模态跳转

可以实现任意View之间的跳转
用模态跳转下一页:
1.在这个页面中创建下一个ViewController页面,并建一个button
原代码:

UIButton *button =[UIButton buttonWithType:UIButtonTypeSystem];
    button.frame =CGRectMake(240, 600, 100, 40);
    button.layer.borderWidth=1;
    button.layer.cornerRadius=10;
    [self.view addSubview:button];
    [button setTitle:@"下一页" forState:UIControlStateNormal];
  [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

点击button来触发以下的方法:
-(void)click:(UIButton *)button{
SecondViewController *secondView=[[SecondViewController alloc] init];
[secondView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];(这是跳转动画)
[self presentViewController:secondView animated:YES completion:^{
}];(实现跳转)
[secondView release];
}

建立SecondViewController这个类和页面,实现从本页面(self)到第二个页面(secondVC)的跳转

在第二个页面调回第一个页面

-(void)click:(UIButton *)button{
 [self dismissViewControllerAnimated:YES       completion:^{   
}];
}

第二种方法

通过导航控制器进行跳转

之前建立新类和button和模态跳转一样
之后实现跳转方法:
原代码:

-(void)click:(UIButton *)button{
 SecondViewController *secondView=[[SecondViewController alloc] init];
[self.navigationController pushViewController:secondView animated:YES];
    [secondView release];
    }

跳回方法

-(void)click1:(UIButton *)button{
    [self.navigationController popViewControllerAnimated:YES];
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值