gpt4 book ai didi

iphone - 如何关闭多个存在的 Modal ViewController 并返回到根 Tab Bar Controller ?

转载 作者:可可西里 更新时间:2023-11-01 05:48:14 24 4
gpt4 key购买 nike

我有一个在启动时显示 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];
}

现在在我的谷歌搜索中,我遇到了我不熟悉的委托(delegate)概念。有人可以花时间帮助我解决我的困境。

提前致谢

最佳答案

View Controller 以堆栈的形式组织。您使用 UINavigationController方法 popToRootViewControllerAnimated: 或 popToViewController:animated: 来控制从堆栈顶部弹出多少 View 。

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

将所有 View Controller 弹出到 Root 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 - 如何关闭多个存在的 Modal ViewController 并返回到根 Tab Bar Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5773341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com