Iphone 如何关闭多个PresentModalViewController并返回根选项卡栏控制器?
我有一个应用程序,在启动时显示presentModalViewControllerIphone 如何关闭多个PresentModalViewController并返回根选项卡栏控制器?,iphone,ios,delegates,uiviewcontroller,modal-dialog,Iphone,Ios,Delegates,Uiviewcontroller,Modal Dialog,我有一个应用程序,在启动时显示presentModalViewController - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // Add the tab bar co
- (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和控制器都消失,这样我就可以返回根控制器,它是一个选项卡栏控制器
我已尝试执行以下操作,但无效:
-(IBAction) btnSubmitLoginPassword{
//make web service call
// [self dismissModalViewControllerAnimated:YES];
[self.tabBarController dismissModalViewControllerAnimated:YES];
}
现在在我的谷歌搜索中,我遇到了我不熟悉的代表概念。有人能抽出时间帮我解决我的困境吗
提前感谢添加
id代表
和@property(非原子,保留)id委托代码>在您的概述中。在概览中添加@synthesis delegate
。然后在initWithNibName:bundle
之后添加以下内容:
[overviewViewController setDelegate: self];
[overviewViewController setDelegate: self];
对登录类执行相同的操作:
添加id委托
和@property(非原子,保留)id委托代码>在您的登录名中。在登录名中添加@synthesis delegate
。然后在initWithNibName:bundle
之后添加以下内容:
[overviewViewController setDelegate: self];
[overviewViewController setDelegate: self];
在概述中添加以下方法。m:
- (void)dismissLoginView {
[self dismissModalViewControllerAnimated: NO];
[delegate dismissModalViewControllerAnimated: YES];
}
将您的-(iAction)btnSubmitLoginPassword
更改为
-(IBAction) btnSubmitLoginPassword {
[delegate dismissLoginView];
}
我还没有测试过。我希望它能起作用!如果没有,请告诉我。视图控制器以堆栈形式组织。您可以使用方法popToRootViewControllerAnimated:或popToViewController:animated:来控制从堆栈顶部弹出的视图数量
您可以通过应用程序委托访问UINavigationController实例
将所有视图控制器弹出到根视图控制器:(我想这就是您要问的)
要将所有视图控制器弹出到堆栈中的已知视图控制器,请执行以下操作:
UIApplicationDelegate* delegate = [[UIApplication sharedApplication] delegate];
[delegate.navigationController popToViewController:popToViewController animated:YES];
它适用于任何类型的视图,尽管我不知道你所说的“模态视图”是什么意思……我指的是通过调用方法presentModalViewController:animated加载的视图控制器。对不起,我错过了你使用presentModalViewController的地方。我真的不知道,但我想知道。。。不。为什么不将代码改为使用pushViewController:animated:呢?我不是问这个问题的人。