简体   繁体   English

如何更改当前视图控制器?

[英]How to change the present view controller?

I have a login view controller which make a request to the server for authentification. 我有一个登录视图控制器,它向服务器发出请求进行身份验证。 Once it is success, I want the present view controller to be the home tab view controller of my application. 一旦成功,我希望当前的视图控制器成为我的应用程序的主选项卡视图控制器。 I did try to use pushViewController:viewController or presentModalViewController or dismissModalViewControllerAnimated. 我确实尝试过使用pushViewController:viewController或presentModalViewController或dismissModalViewControllerAnimated。 Nothing works. 什么都没有。 You can take a look at the screenshot provided to understand my application flow. 您可以看一下提供的屏幕截图,以了解我的应用程序流程。

Here is some sample code: 这是一些示例代码:

- (IBAction)facebookLoginButtonClick:(id)sender {

// get the app delegate so that we can access the session property
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];

// this button's job is to flip-flop the session from open to closed
if (appDelegate.session.isOpen) {
    // if a user logs out explicitly, we delete any cached token information, and next
    // time they run the applicaiton they will be presented with log in UX again; most
    // users will simply close the app or switch away, without logging out; this will
    // cause the implicit cached-token login to occur on next launch of the application
    [appDelegate.session closeAndClearTokenInformation];

} else {
    if (appDelegate.session.state != FBSessionStateCreated) {
        // Create a new, logged out session.
        appDelegate.session = [[FBSession alloc] init];
    }

    // if the session isn't open, let's open it now and present the login UX to the user
    [appDelegate.session openWithCompletionHandler:^(FBSession *session,
                                                     FBSessionState status,
                                                     NSError *error) {
        // and here we make sure to update our UX according to the new session state
        [self dismissModalViewControllerAnimated:YES];
        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle: nil];
        MainViewTabBarController *viewController = (MainViewTabBarController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"mainPageTabBarId"];
        [[self navigationController] presentModalViewController:viewController animated:YES];
    }];
}

} }

在此处输入图片说明

Figure out the solution. 找出解决方案。 Instead of push the model view controller, I should change the rootViewController in the application delegate. 我应该在应用程序委托中更改rootViewController,而不是推送模型视图控制器。 It works well. 它运作良好。 Thanks for the help from everyone. 感谢大家的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UILongPressGestureRecognizer如何将当前视图更改为另一个视图控制器? - how can a UILongPressGestureRecognizer change the present view to another View Controller? 如何在没有“当前”视图控制器的情况下在iphone上呈现模态视图控制器? - How to present a modal view controller on the iphone without a “current” view controller? 如何显示视图控制器上存在的UIButton - How to show UIButtons present on the view controller 如何使用固定的UIToolbar呈现模态视图控制器? - How to present a modal view controller with fixed UIToolbar? 如何将GKMatchmakerViewController呈现给呈现的视图控制器? - How to present GKMatchmakerViewController to presented view controller? 当前模态视图控制器 - present modal view controller 如何更改布局视图控制器? - how to change layout view controller? 如何更改特定视图的视图控制器的方向 - how to change the orientation of a view controller for specific view 当应用程序进入前台时如何呈现模态视图控制器? - How to present a modal view controller when the app enters in foreground? 如何使用swift清除和重绘UIView(存在于视图控制器中)的内容? - How to clear and redraw contents of a UIView (present inside a view controller) with swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM