如何在不使用Xcode中的按钮单击的情况下更改屏幕

时间:2014-05-22 21:33:24

标签: ios objective-c uistoryboard

我想在有人成功登录时更改屏幕。我知道如何访问我的控制器类而不是特定的屏幕。

[NRGramKit loginInWebView:self.webView loginLoadingCallback:^(BOOL loading){
    NSLog(@"Loading");

} finishedCallback:^(IGUser* user,NSString* error){
    // yay - you are now authenticated, NRGramKit remembers the credentials
    LoggedInViewController *loggedInViewController = [[LoggedInViewController alloc]init];
    loggedInViewController.myUser = user;
    [self presentViewController:loggedInViewController animated:YES completion:nil];

}];

1 个答案:

答案 0 :(得分:0)

您可以在instantiateViewControllerWithIdentifier:的实例上使用UIStoryboard方法以编程方式从故事板中实例化视图控制器。

UIStoryboard *myStoryboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:nil];
MyViewController *vc = [myStoryboard instantiateViewControllerWithIdentifier:@"Page"];
// use view controller and its view as required

UIViewController -storyboard

如果您的视图控制器来自故事板,那么storyboard属性将返回它来自的故事板。所以你可以跳过故事板初始化。

// within a view controller
OtherViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"OtherIdentifier"];

设置标识符

  • open storyboard
  • 选择视图控制器
  • open identity inspector(可以设置子类的面板)
  • 设置“故事板ID”

Setting the view controller's storyboard ID