视图间的两种跳转步骤
视图间的两种跳转方法
视图之间一共有两种跳转方法
第一种方法
模态跳转
可以实现任意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)的跳转
第二种方法
通过导航控制器进行跳转
之前建立新类和button和模态跳转一样
之后实现跳转方法:
原代码:
-(void)click:(UIButton *)button{
SecondViewController *secondView=[[SecondViewController alloc] init];
[self.navigationController pushViewController:secondView animated:YES];
[secondView release];
}
版权声明:本文为博主原创文章,未经博主允许不得转载。