【发布时间】:2015-10-01 16:06:53
【问题描述】:
Xcode 7.0.1
更新:
我尝试的最新方法是分解 UINavigationController 的创建:
self.viewController = [[ProjectsViewController alloc] initWithNibName:@"ProjectsViewController_iPhone" bundle:nil];
self.navigationController = [[UINavigationController alloc] init];
[self.navigationController setViewControllers:@[self.viewController]];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
这样做会导致崩溃
[self.window makeKeyAndVisible];
但痕迹完全一样。
我也通过更改尝试使用香草 ViewController 进行此操作
[self.navigationController setViewControllers:@[[[UIViewController alloc] init]]];
同样的结果...
原帖:
我遇到了一个我很难理解的崩溃 - 这是 lldb 跟踪:注意 2147483648
的索引*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM removeObjectAtIndex:]: index 2147483648 beyond bounds [0 .. 2]'
*** First throw call stack:
(
0 CoreFoundation 0x035eaa94 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x03084e02 objc_exception_throw + 50
2 CoreFoundation 0x034f92ed -[__NSArrayM removeObjectAtIndex:] + 445
3 UIKit 0x018c20b2 -[UIView(Hierarchy) bringSubviewToFront:] + 260
4 UIKit 0x0193daeb -[UINavigationBar layoutSubviews] + 3692
5 UIKit 0x018d716b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 813
6 libobjc.A.dylib 0x03099059 -[NSObject performSelector:withObject:] + 70
7 QuartzCore 0x0096e60c -[CALayer layoutSublayers] + 144
8 QuartzCore 0x0096228e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 388
9 QuartzCore 0x00970b2c -[CALayer(CALayerPrivate) layoutBelowIfNeeded] + 44
10 UIKit 0x018c4dca -[UIView(Hierarchy) layoutBelowIfNeeded] + 1244
11 UIKit 0x01a117cf __74-[UINavigationController _positionNavigationBarHidden:edge:initialOffset:]_block_invoke + 36
12 UIKit 0x018caca6 +[UIView(Animation) performWithoutAnimation:] + 82
13 UIKit 0x01a1178d -[UINavigationController _positionNavigationBarHidden:edge:initialOffset:] + 922
14 UIKit 0x01a1194c -[UINavigationController _positionNavigationBarHidden:edge:] + 326
15 UIKit 0x01a12d5f -[UINavigationController _positionNavigationBarHidden:] + 49
16 UIKit 0x01a1104a -[UINavigationController setNavigationBar:] + 1224
17 UIKit 0x01a10a38 -[UINavigationController _navigationBarHiddenByDefault:] + 156
18 UIKit 0x01a10997 -[UINavigationController navigationBar] + 41
19 UIKit 0x01a17805 -[UINavigationController loadView] + 230
20 UIKit 0x019d3338 -[UIViewController loadViewIfRequired] + 138
21 UIKit 0x019d3cf1 -[UIViewController view] + 35
22 UIKit 0x01a22226 -[UINavigationController pushViewController:transition:forceImmediate:] + 615
23 UIKit 0x01a21e27 __54-[UINavigationController pushViewController:animated:]_block_invoke + 351
24 UIKit 0x01a21c83 -[UINavigationController pushViewController:animated:] + 786
25 UIKit 0x01a07be2 -[UINavigationController initWithRootViewController:] + 140
26 DELETIA 0x0012954e -[AppDelegate application:didFinishLaunchingWithOptions:] + 1214
这是一个成熟的应用程序,已经构建和运行了一段时间,但在当前的 XCode 中发生了上述情况。
如您所见,调用了 UINavigationController:initWithRootViewController - 这是代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// deletia - non UIKit code
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.tintColor = [UIColor darkGrayColor];
self.viewController = [[ProjectsViewController alloc] initWithNibName:@"ProjectsViewController_iPhone" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
// deletia - but the app crashes on the above line
}
在查看了一些类似的问题后,我尝试了一些事情,并且 答案在这里。
我听说如果基于 View 控制器的状态栏会发生这种情况 在 Info.plist 中外观设置为 YES - 所以我将其设置为 NO / 是的
我听说某些 UIGestureRecognizer 会导致问题 - 所以我检查了 XIB 并确保没有影响此视图控制器。
我听说如果根视图控制器没有完全初始化 这可能有问题 - 所以我推迟了对 UINavigationController 1 秒
-
我误信了 ProjectsViewController - 所以我用它代替了 一个香草 UIViewController 因此:
self.navigationController = [[UINavigationController alloc] initWithRootViewController:[[UIViewController alloc] init]];
非常感谢任何见解;无论是可能导致问题的原因,还是可能对问题有所启发的调试技术。
【问题讨论】:
-
我注意到 2147483648 是 0x80000000 但不明白。您是否向 UINavigationBar 添加了系统尝试删除的任何内容?也许尝试在导航栏上添加一个按钮,看看是否有任何变化?
-
@ishahak 你的意思是在 xib 中吗?
-
是的,因为崩溃堆栈显示 UINavigationBar 正在运行它的“layoutSubviews”处理程序 -> BringSubviewToFront -> removeObjectAtIndex。不知道它为什么要从数组中删除某些东西,但我会尝试用更多元素填充这个数组(导航栏的子视图)。如果不太复杂,我个人会尝试重新创建 XIB。
-
hmm - XIB 真的很简单(根本没有导航组件) - 我可以回溯到旧版本(大约一年前 tbh)并执行它 ok - 我检查并没有更改即 XIB(或在 App Delegate 中,而不是在上述所有操作之后添加 crashalytics)
-
看起来有些东西(也许在代码中)要求将子视图放在前面。我想这是在其父视图中询问视图的索引并要求将其删除,以便它可以在最后添加它。搜索必须返回 NSNotFound,它是 2147483648(最大整数值),然后它使用它来进行删除。看起来您应该专注于 NavigationBar 和与栏相关的任何代码。它似乎在位置导航栏隐藏。默认是隐藏的吗?
标签: ios objective-c debugging uikit