Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 调试UIKit崩溃[UINavigationController initWithRootViewController]_Ios_Objective C_Debugging_Uikit - Fatal编程技术网

Ios 调试UIKit崩溃[UINavigationController initWithRootViewController]

Ios 调试UIKit崩溃[UINavigationController initWithRootViewController],ios,objective-c,debugging,uikit,Ios,Objective C,Debugging,Uikit,Xcode 7.0.1 更新: 我最近尝试的一件事是分解UINavigationController的创建,因此: self.viewController = [[ProjectsViewController alloc] initWithNibName:@"ProjectsViewController_iPhone" bundle:nil]; self.navigationController = [[UINavigationController alloc] init]; [se

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.navigationController = [[UINavigationController alloc] initWithRootViewController:[[UIViewController alloc] init]];
这样做的话,坠机现在开始了

[self.window makeKeyAndVisible];
但痕迹完全相同

我也尝试过通过更改Villa 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
}
在看了一些类似的问题之后,我尝试了一些方法 答案就在这里

  • 我听说,如果基于状态栏查看控制器,可能会发生这种情况 外观在Info.plist中设置为“是”,因此我将其设置为“否”/ 对

  • 我听说一些UIgestureRecognitor可能会导致问题,所以我检查了XIB,并确保没有影响此视图控制器的因素

  • 我听说如果根视图控制器没有完全初始化 这可能会有问题,所以我推迟了对 UINavigationController延迟1秒

  • 我不信任ProjectsViewController,所以我用它来代替它 因此,一个普通的控制器:

      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.navigationController = [[UINavigationController alloc] initWithRootViewController:[[UIViewController alloc] init]];
    

任何见解都值得赞赏;无论是在可能导致问题的原因方面,还是在调试技术方面,都可能对问题有所帮助。

我认为您关注的是错误的代码。正如您所提到的,它在
[self.window makekey and visible]
行上崩溃,但是,可能是这一行导致
ProjectsViewController
UINavigationController
对象加载并呈现给用户。查看您发布的崩溃日志,这是您应该调查的部分:

2   CoreFoundation                      0x034f92ed -[__NSArrayM removeObjectAtIndex:] + 445
3   UIKit                               0x018c20b2 -[UIView(Hierarchy) bringSubviewToFront:] + 260
4   UIKit                               0x0193daeb -[UINavigationBar layoutSubviews] + 3692
您可以在这里看到,iOS试图布局UINavigationBar的子视图,然后删除索引处的对象,该索引可能是
NSNotFound
(这将导致
NSIntegerMax
,它与您在崩溃日志中提到的索引相匹配)

为了进一步研究这次事故,我建议采取以下步骤:

  • ProjectsViewController
    实例替换为不带自定义.xib文件的
    UIViewController
    实例。(我在你原来的帖子中读到,你已经尝试过了,但我还是建议你作为第一步来做,以便在完全解决崩溃的过程中消除更多问题(如果不止一个问题的话)。务必确保此时未使用.xib文件,因为这可能是导致崩溃的原因(如果存在任何链接错误或类似问题)
  • 您的导航栏中是否显示任何项目?同样,我注意到您在评论中提到它没有,但我会仔细检查,看看是否有一个代码部分,其中的项目在某些条件下被添加到栏中,如果不满足,则被删除。如果试图从无效索引中删除项目,则可能会导致崩溃
  • 尝试在代码中搜索专门调用
    removeObjectAtIndex
    的位置,或在初始视图控制器的加载和显示过程中可能调用的任何其他
    NSMutableArray
    相关调用。在这些位置添加一个断点,以查看在初始加载过程中是否达到这些位置。如果是这样,请尝试在那里添加一个测试,以确保要从中删除对象的索引大于或等于零,并且小于数组的大小。这样,如果您试图访问的索引是
    NSNotFound
    ,它至少不会导致应用程序崩溃(不管当前崩溃情况如何,这是一个很好的做法)。如果这最终解决了问题,那么您可以进一步调查该问题,并尝试了解为什么实际接收到
    NSNotFound
    作为索引,并从逻辑上解决该问题

  • 我希望这些步骤中的一个可以帮助确定和解决您的问题。祝你好运

    UINavigationController
    是一个堆栈,您只能在其中推送和弹出
    UIViewController
    。您应该在启动导航控制器时传递一个
    UIViewController
    。但是如果您不知道RootViewController,那么您可以这样做

    self.viewController = [[ProjectsViewController alloc] initWithNibName:@"ProjectsViewController_iPhone" bundle:nil];
      self.navigationController = [[UINavigationController alloc] init];
      [self.navigationController pushViewController:self.viewController animated:NO];
      self.window.rootViewController = self.navigationController;
      [self.window makeKeyAndVisible];
    

    我注意到2147483648是0x8000000,但我不理解它。您是否向UINavigationBar添加了系统试图删除的内容?也许尝试向导航栏添加一个按钮,看看是否有任何变化?@Ishahahak你是说在xib中?是的,因为崩溃堆栈显示UINavigationBar正在运行其“layoutSubviews”处理程序->bringSubviewToFront->removeObjectAtIndex。我不知道为什么它想从数组中删除一些东西,但我会尝试用更多的元素填充这个数组(导航栏的子视图)。如果不是太复杂的话,我个人会尝试重新创建XIB。嗯-XIB非常简单(根本没有导航组件)-我可以回溯到旧版本(大约一年前tbh)并执行ok-我检查了,并且在该XIB上没有任何更改(或者在应用程序委托中,除了上面所有添加的crashalytics之外)看起来好像有什么东西(可能在代码中)要求将子视图放到前面。我想这是在父视图中请求视图的索引,并请求删除它,以便在最后添加它。搜索必须返回NSNotFound,即2147483648(最大整数值),然后使用该值进行删除。看起来您应该关注导航栏以及与导航栏相关的任何代码。它似乎在导航位置