presentModalViewController

presentModalViewController

我有一个在启动时显示 presentModalViewController 的应用程序。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    // Add the tab bar controller's view to the window and display.
    [self.window addSubview:tabBarController.view];
    Overview *overviewViewController = [[Overview alloc] initWithNibName:@"Overview" bundle:nil];
    [self.tabBarController presentModalViewController:overviewViewController animated:YES];
    [overviewViewController release];
    [self.window makeKeyAndVisible];
    return YES;
}

一旦显示了overviewController,用户就可以登录或注册。如果他们选择登录,那么我使用另一个 presentModalViewController 让他们登录:
  -(IBAction) btnLoginPressed{

//  [self dismissModalViewControllerAnimated:YES];
    Login *loginOverView = [[Login alloc] initWithNibName:@"Login" bundle:nil];
    [self presentModalViewController:loginOverView animated:YES];
    [loginOverView release];


}

但是,在成功登录后,我希望 presentModalViewController 消失,让我返回到作为选项卡栏 Controller 的根 Controller 。

我尝试执行以下操作,但不起作用:
-(IBAction) btnSubmitLoginPassword{

    //make web service call
//  [self dismissModalViewControllerAnimated:YES];
    [self.tabBarController dismissModalViewControllerAnimated:YES];
}

现在在我的谷歌搜索中,我遇到了我不熟悉的代表的概念。有人可以花时间帮助我解决我的困境吗?

提前致谢

最佳答案

View Controller 被组织在一个堆栈中。您可以使用 UINavigationController 方法 popToRootViewControllerAnimated: 或 popToViewController:animated: 来控制从堆栈顶部弹出的 View 数量。

您可以通过应用程序委托(delegate)访问 UINavigationController 实例。

将所有 View Controller 弹出到根 View Controller :(我认为这就是您要问的)

UIApplicationDelegate* delegate = [[UIApplication sharedApplication] delegate];
[delegate.navigationController popToRootViewControllerAnimated:YES];

要将所有 View Controller 弹出到堆栈中的已知 View Controller :
UIApplicationDelegate* delegate = [[UIApplication sharedApplication] delegate];
[delegate.navigationController popToViewController:popToViewController animated:YES];

关于iphone - 如何关闭多个presentModalViewControllers并返回根标签栏 Controller ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5773341/

10-09 02:23