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

时间:2015-04-22 04:45:37

标签: ios objective-c 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];
     }
}

5 个答案:

答案 0 :(得分:0)

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

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

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

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

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

答案 1 :(得分:0)

您没有将“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];

答案 2 :(得分:0)

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

UIViewController *vc = self.window.rootViewController;

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

答案 3 :(得分:0)

如果您使用XIB的

,请按如下所示修改代码
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
AnotherViewController *anothervc = [[AnotherViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil];
[navController.visibleViewController.navigationController pushViewController: Anothervc animated:YES]; 

// StoryBoards..Main是storyBoard的名字..!

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

希望它可以帮助你......!

答案 4 :(得分:0)

UIViewController * vc = self.window.rootViewController;

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

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