使用Segue能够在ViewController之间来回切换,以下就来说下切换方法:

1、使用点击button进行切换

直接上图,在须要切换的View属性界面,点击Modal然后拉到前一个view界面或者是Button上

20140423150126765.jpg

2、 手动进行跳转

假设拉到了Button的TouchUpInside上,那么点击左側button的时候就会切到右边的View,假设拉到了view上,就会连接Manual,在代码中实现跳转

20140423150126765.jpg

设置Segue的Indentifier属性:

20140423150126765.jpg

代码中手动进行跳转:

//在viewDidAppear里面加入触发segue进行自己主动跳转
-(void)viewDidAppear:(BOOL)animated
{
    [self performSegueWithIdentifier:@"drawecg" sender:self];
}

注:在ViewDidLoad实现跳转无效

  1. 怎样跳转到随意一个页面

在有可能进行上级跳转的ViewController文件里加上以下代码,函数名称任起:

#pragma mark 定义这个函数,别的ViewController在Exit的时候就能直接跳到这了
- (IBAction)goHome:(UIStoryboardSegue *)segue
{
    [[segue sourceViewController] class];
}

在想要跳转view的Exit上右键,选择这个goHome函数,拉到想要运行的button上,就能够实现跳转了

20140423150126765.jpg

也可代码实现返回上一个页面,注销当前页面:

-(void)lastPage
{
    NSLog(@"点击了上一个视图button");
    [self dismissViewControllerAnimated:YES completion:^(void){
        // Code
    }];
}

也可这样实现:

 // 获取故事板
 UIStoryboard *board = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
 // 获取故事板中某个View    
 UIViewController *next = [board instantiateViewControllerWithIdentifier:@"Second"];
 // 跳转    
 [self presentModalViewController:next animated:YES];

当然,假设你使用Navigation Controller,使用Push进行连接,就不是上面的代码进行跳转了:

跳转到LandscapeViewController

//打开一个横屏界面
- (IBAction)openLandscapeControl:(id)sender {
    LandscapeViewController *control = [[LandscapeViewController alloc]initWithNibName:@"LandscapeViewController" bundle:nil];
    [self.navigationController pushViewController:control animated:YES];
}

使用pop返回上一个View

//返回前一页
- (IBAction)clickBack:(id)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
}
你可能感兴趣的内容
0条评论

dexcoder

这家伙太懒了 <( ̄ ﹌  ̄)>
Owner