【发布时间】:2014-08-06 18:21:29
【问题描述】:
我有一个基于UITabBarController 的应用程序,其中我的登录页面 由默认选项卡的VC(UITabBarController 索引0)以模态方式呈现,并由dismissViewControllerAnimated: 以模态方式关闭。
从我的设置页面我有一个注销按钮,如果用户立即重新登录,我必须调用[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];,然后重置UITabBarController' s selectedIndex 属性,以便摆脱设置页面并返回到开始的 tabBar 选项卡。所以我这样做:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString* responseString = [[NSString alloc] initWithData:_responseData encoding:NSUTF8StringEncoding];
/*Succesful Login*/
if([responseString isEqualToString:@"success"])
{
UITabBarController *tabBarController = (UITabBarController *)self.presentingViewController;
if (tabBarController){
NSLog(@"I have a tab bar~");
[self.tabBarController setSelectedIndex:0];
}
else{
NSLog(@"I don't have a tab bar~");
}
//dismisses from a second, immediate, re-login attempt
[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
//dismisses from first login attempt
[self dismissViewControllerAnimated:YES completion:nil];
NSLog(@"Succesful login.");
}
在这种情况下,setSeletedIndex: 方法不起作用,因为该方法本质上是创建 tabBarController 的一个新实例,而实际显示的是原始实例。我似乎无法访问已经存在的 UITabBarController,它位于我的模态显示登录页面之前。
编辑:
我已经尝试使用这个条件来检查它的存在:
if (self.tabBarController){
NSLog(@"I have a tab bar~");
//[self.tabBarController setSelectedIndex:0];
}
else{
NSLog(@"I don't have a tab bar~");
}
我什至将 self.tabBarController 更改为 self.presentingViewController.tabBarController 并获得 nil 和 self.presentingViewController.presentingViewController.tabBarController 并获得 nil,我如何访问以前存在的 @987654329 @?
目标: 访问应用程序的 UITabBarController,它出现在登录页面之前。 (访问 Appdelegate 的 UITabBarController)
【问题讨论】:
-
您发布的代码中没有任何内容可以创建标签栏控制器的新实例。如果你记录 self.presentingViewController 和 self.tabBarController 它们会给你什么?另外,根据您的描述,听起来您已经在索引 0 的选项卡上(显示模态),那么您期望 setSelectedIndex:0 会做什么?
-
找到了答案,而 self.tabBarController 给了我零,这就是问题所在..
-
您的问题不清楚。请注意,人们会花时间来帮助您。您至少可以澄清您的问题,以便更轻松地为您提供“解决方案”。祝你好运。
-
不,我感谢您的帮助,并为不清楚的地方感到抱歉,这是我第一次不得不处理这个问题,这真的很令人困惑。我不得不重新配置我的整个应用程序,感谢您抽出宝贵时间。
标签: ios objective-c uitabbarcontroller modalviewcontroller