iOS 从一个syoryBoard 跳转到另一个stroyBoard 方法简介

来源:互联网 发布:mac 画架构图工具 编辑:程序博客网 时间:2024/05/18 14:42

//在多个story中根据storyBoard 名字找到需要的主入口stroBoard 代码如下:


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [self.window makeKeyAndVisible];
    
    //获取storyboard
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"LoginAndRegister" bundle:nil];
    //获取入口的控制器
    UIViewController *lavc = [storyboard instantiateInitialViewController];
    //通过标示获取控制器
//    UIViewController *lavc1 = [storyboard instantiateViewControllerWithIdentifier:<#(nonnull NSString *)#>]
    
    [self.window.rootViewController presentViewController:lavc animated:YES completion:nil];
    
    
    return YES;
}

//从一个storyBoard中某个页面 跳转到另一个storyBoard页面中的某一个页面:

//本例是从 Main页面中的storyBoard 中的哟个页面跳转到LoginAndRegiste storyBoard中的一个页面  在Main 页面中设置一个Button 再点击事件中实现跳转;需要注意的是没有NAvigation 的需要模态过去

- (IBAction)giveLogin:(id)sender {
    
    //@"LoginAndRegister" 为storyBoard 名 @"login"为 需要跳转控制器在storBoard上的storyBoard ID  (dianstory 右上第三个关联下面的ID ) LoginViewController
    
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"LoginAndRegister"bundle:nil];
    
    UIViewController *login = [story instantiateViewControllerWithIdentifier:@"login"];
    
    
    [self.navigationController pushViewController:login animated:YES];
    
}


0 0
原创粉丝点击