控制器之间的跳转

1.代码跳转,vc的界面需要写在xib上

UIViewController *vc = [[UIViewController alloc] init];//普通控制器

[self presentViewController:vc animated:YES completion:nil];

2.storyboard按钮跳转,无连线,也可以传值
- (IBAction)itemClick:(id)sender {
    UIViewController *three = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"three"];
    [self presentViewController:three animated:YES completion:nil];
}

3.storyboard直接将第一个控制器按钮拖到第二个控制器 选择show.点击即跳转

4.storyboard二个控制器相连,有个segue设置Identifier,通过代码跳转:
[self performSegueWithIdentifier:@"segue" sender:self];
    并且可以通过prepareForSegue:方法传值.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // segue.identifier:获取连线的ID
    if ([segue.identifier isEqualToString:@"SendValue"]) {
        // segue.destinationViewController:获取连线时所指的界面(VC)
        ReceiveViewController *receive = segue.destinationViewController;
        receive.name = @"Garvey";
        receive.age = 110;
        // 这里不需要指定跳转了,因为在按扭的事件里已经有跳转的代码
        //        [self.navigationController pushViewController:receive animated:YES];
    }
}

 

你可能感兴趣的:(控制器之间的跳转)