如何为 .xib 编写这个主要故事板代码?

How to write this main story board code for .xib?

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    if (applicationIsActive) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Bildirim"
                                                            message:[NSString stringWithFormat:@"%@ ",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]
                                                           delegate:self cancelButtonTitle:@"Ok" 
                                                  otherButtonTitles:nil];
        [alertView show];

        UIViewController *vc = self.window.rootViewController;
        AnotherViewController *Anothervc = [Anothervc.storyboard instantiateViewControllerWithIdentifier:@"AnotherViewController "];

        [vc presentViewController:Anothervc animated:YES completion:nil];
     }
}

您可以通过以下代码获取任何storyboard对象。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

现在在故事板对象的帮助下呈现控制器。

AnotherViewController *Anothervc = [storyboard instantiateViewControllerWithIdentifier:@"AnotherViewController"];

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

您没有将 "AnotherViewController" 添加到 MainStoryboard。 尝试像下面这样获取 MainStoryboard 的对象

UIStoryboard *sb= [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

然后修改你的

AnotherViewController *Anothervc = [Anothervc.storyboard instantiateViewControllerWithIdentifier:@"AnotherViewController"];

AnotherViewController *Anothervc = [sb instantiateViewControllerWithIdentifier:@"AnotherViewController "];

现在展示它

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

如果你正在使用 XIB,试试这个,

UIViewController *vc = self.window.rootViewController;

AnotherViewController *anothervc = [[AnotherViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil];
[vc presentViewController:anothervc animated:YES completion:nil];

如果您使用的是 XIB,请修改如下代码

UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
AnotherViewController *anothervc = [[AnotherViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil];
[navController.visibleViewController.navigationController pushViewController: Anothervc animated:YES]; 

//StoryBoards..Main是故事板名称..!

UIViewController *vc = self.window.rootViewController;   
AnotherViewController *Anothervc = [[UIStoryboard storyboardWithName:@"Main" bundle: nil] instantiateViewControllerWithIdentifier:@"AnotherViewController"];                                                                     
[vc presentViewController:Anothervc animated:YES completion:nil];

希望对你有帮助..!

UIViewController *vc = self.window.rootViewController;

AnotherViewController *Anothervc = [storyboard instantiateViewControllerWithIdentifier:@"AnotherViewController"];

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