- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的应用程序包含一些 UIViewControllers
。第一个是登录页面,第二个是“菜单页面”,第三个是 viewController
。
我在每个页面的按钮上放置了一个注销功能,带有如下所示的 alertView:
- (IBAction)logout:(id)sender {
UIAlertView *logoutConfirm = [[UIAlertView alloc] initWithTitle: @"Logout" message: @"Sure ? " delegate: self cancelButtonTitle: @"Ok" otherButtonTitles:@"Cancel", nil];
[logoutConfirm show];
}
// Logout
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// Logs to track the bug
NSLog(@"LOG :%@", [self.navigationController viewControllers]);
NSLog(@" LOG 2 : %@", [self.navigationController.viewControllers objectAtIndex:0]);
if (buttonIndex == 0) {
[self.navigationController popToRootViewControllerAnimated:NO];
}
}
popToRootViewControllerAnimated
使应用程序在第三个 ViewController
上崩溃,但在第二个上没有此消息:
Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'adding a root view controller <MainViewController: 0xXXXXXX> as a child of view controller:<UINavigationController: 0xXXXXXX>'
有我的日志:
2014-09-25 10:24:35.074 Poject[18594:654203] LOG :(
"<MainViewController: 0xXXXXXXX>",
"<secondViewController: 0xXXXXXXX>",
"<thirdViewController: 0xXXXXXXX>"
)
2014-09-25 10:24:35.075 Poject[18594:654203] LOG 2 : <MainViewController: 0xXXXXXXX>
似乎我正在添加一个 UIViewController
,但只是想回到第一个 viewController ...我认为如果它在第二个 ViewController 上工作而不是在第三个 ViewController 上工作很奇怪 ...
更新
@mehul patel 让我在我的 AppDelegate.h 中评论这一行:
[self.window addSubview:self.navigationController.view];
因为:
You can not add your rootViewController as subview to window, it will crash in any way
但是现在,我的 firstViewController 中“登录按钮”上的 pushViewController 不再起作用了。它什么都不做,所以我 NSLog 我的 navigationController 的 Controller 数组
我第一次得到:
2014-09-25 16:48:07.512 Project[22023:780717] (
"<MainViewController: 0xf81f290>"
)
我第二次得到:
2014-09-25 16:48:12.104 Project[22023:780717] (
"<MainViewController: 0xf81f290>",
"<MenuSelectionViewController: 0xd929030>"
)
但是, View 并没有改变......
感谢您的帮助!
最佳答案
试试这个
- (void) logout {
@try {
NSArray *controllers = [self.navigationController viewControllers];
if (controllers && [controllers count] > 0) {
UIViewController *loginController = [controllers objectAtIndex:0];
[self.navigationController popToViewController:loginController animated:YES];
}
}
@catch (NSException *exception) {
// Throws an exception
}
}
关于ios - popToRootViewControllerAnimated 使我的应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26034055/
我有一个 UITabBarController,其选项卡是 UINavigationController。我已经通过以下方式初始化了每个导航 Controller : iPhoneApp *appD
我的应用程序包含一些 UIViewControllers。第一个是登录页面,第二个是“菜单页面”,第三个是 viewController。 我在每个页面的按钮上放置了一个注销功能,带有如下所示的 al
我有 View A、 View B 和 View C。我已从 View A 推送 View B,并从 View B 推送 View C。 当用户点击 View C 中的后退按钮时,我调用 popToR
我在尝试切换到另一个 VC 时遇到了崩溃。这是结构: TabBarController [主页、Tab2、结果选项卡] 从这些选项卡中,我可以推送一个名为 addVC 的新 viewControlle
我的应用程序中有一个通过单击按钮启动的数据下载过程。该操作发生在后台线程上,因此用户可以自由导航到其他 View 并按照自己的喜好进行操作。 下载完成后,系统会向用户显示警告,提示应用需要重新加载。单
我在我的应用程序中使用 navigationController。在我推送并弹出 View Controller 3 次后,我的应用程序因内存不足而崩溃。这是我的代码。 - (BOOL)applica
在我的 StoryBoard 中,我将 Root View Controller 嵌入到导航 Controller 中,该 View 在应用程序启动时显示。然后用户浏览一系列 View ,这些 Vie
我有两个 View ,一个是 Root View Controller ,另一个是搜索 View Controller 。当我在搜索 viewController 的 UISearchBar 上单击取
我正在制作我的 SpriteKit 游戏。当玩家死亡时,我的目标是让游戏转换回开始屏幕。这是通过下面的代码完成的。但是,我注意到每次新游戏开始时内存都会增加。 Xcode Instruments 没有
我有一个 UINavigationController,它要求提供一些信息,并且用户导航直到最后,一旦到达那里,他们就可以接受或取消已输入的所有数据。 他们选择哪个选项并不重要,因为他们总是会使用 进
我编写了一个选项卡栏应用程序,其中第一个选项卡上有一个带有导航 Controller 的表格 View 。 每次我选择一行时,tableviewController 都会被推送。这是服务器上的远程目录
我正在尝试在 iOS 应用程序中实现标签栏: 但是当用户选项卡第 1 项时,我需要释放第二个 viewController。 我设置 UITabBarControllerDelegate - (voi
我无法让 [self.navigationController popToRootViewControllerAnimated:YES]; 工作(无法让我的任何应用程序返回主屏幕)。我尝试创建一个新的
我正在开发一个带有嵌入式导航 Controller 和 UIViewController 的 UITableView 的小型 CoreData 程序,在其中添加 CoreData。 问题是我不知道如何
当我使用该功能时,我被发送回我的 RootViewController,但我的导航栏消失了。当我第一次运行该应用程序时,我的导航栏按预期工作,但是当我登录然后注销时,导航栏消失了。我正在使用顶部栏“推
在我的非根 VC 类中,我有以下 doLogout 方法: - (void)doLogout { SDPAppDelegate *app = [self getAppDelegate];
我想使用 popViewControllerAnimated 而不是 popToRootViewControllerAnimated 来移动到 Root View 。我不想直接移动到 Root Vie
我在 Xcode 6 的 iOS 8 中遇到一个错误。 就是这个场景。 XCode 6 创建新项目“Master-Detail Application” 现在我只是详细地添加了一个按钮,并在其点击事件
我已经实现了一个自定义委托(delegate)方法,如果一些数据从服务器到达,它应该弹出 Root View Controller 。通过单击子 Controller 中的后退按钮,第一种方法 bac
我正在调用 presentModalViewController 的应用程序一旦完成(调用 dismissModalViewControllerAnimated:YES )它应该立即调用 popToR
我是一名优秀的程序员,十分优秀!