ios - 由于位置管理器的原因,展开转场后发生崩溃

标签 ios objective-c iphone uiviewcontroller unwind-segue

我有几个 View Controller 展开到 Root View Controller 。对于大多数 View Controller ,unwind segue 运行良好而不会导致应用程序崩溃。只有使用 CLlocationmanager 的 View Controller 无法对 Root View Controller 执行展开转场。这些是使我的代码与众不同的行:

//Init the location Manager
locationManager = [[CLLocationManager alloc] init];
[locationManager requestWhenInUseAuthorization];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
locationManager.delegate = self;

通过评论我的代码的这一部分,展开工作。特别是最后一行有所不同。我试图在放松之前释放 locationmanager。有时它有效。有时它不会。调试控制台说:

0x10bfe1005:  movq   (%rdi), %r11
0x10bfe1008:  movq   %rsi, %r10
0x10bfe100b:  andl   0x18(%r11), %r10d<---Thread 1: EXC Bad_Access(code=1, adress=0x18)
0x10bfe100f:  shlq   $0x4, %r10
0x10bfe1013:  addq   0x10(%r11), %r10

不管是什么意思。我不知道该怎么办。

编辑

添加这个之后

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
[locationManager stopUpdatingLocation];
[locationManager release];
}

有点效果。我试了 5 次。然后它再次崩溃:(真的很奇怪。不确定,但错误消息似乎已经改变。它说“WebThread”(见下文)。我确实有一个 webview,它也有委托(delegate)方法。我会尝试发布 webview 作为好吧。

libobjc.A.dylib`objc_msgSend:
0x32f9af60:  cbz    r0, 0x32f9af9e            ; objc_msgSend + 62
0x32f9af62:  ldr.w  r9, [r0]
0x32f9af66:  ldrh.w r12, [r9, #12]  <-----WebThread(10):EXC_bad_access(code=1, address=0x100000c)
0x32f9af6a:  ldr.w  r9, [r9, #8]
0x32f9af6e:  and.w  r12, r12, r1
0x32f9af72:  add.w  r9, r9, r12, lsl #3

0x32f9af76:  ldr.w  r12, [r9]
0x32f9af7a:  teq.w  r12, r1
0x32f9af7e:  bne    0x32f9af86                ; objc_msgSend + 38
0x32f9af80:  ldr.w  r12, [r9, #4]
0x32f9af84:  bx     r12
0x32f9af86:  cmp.w  r12, #0x1
0x32f9af8a:  blo    0x32f9af98                ; objc_msgSend + 56
0x32f9af8c:  it     eq
0x32f9af8e:  ldreq.w r9, [r9, #4]
0x32f9af92:  ldr    r12, [r9, #8]!
0x32f9af96:  b      0x32f9af7a                ; objc_msgSend + 26
0x32f9af98:  ldr.w  r9, [r0]
0x32f9af9c:  b      0x32f9b1e0                ; _objc_msgSend_uncached
0x32f9af9e:  mov.w  r1, #0x0
0x32f9afa2:  bx     lr
0x32f9afa4:  nop    
0x32f9afa6:  nop    
0x32f9afa8:  nop    
0x32f9afaa:  nop    
0x32f9afac:  nop    
0x32f9afae:  nop    
0x32f9afb0:  nop    
0x32f9afb2:  nop    
0x32f9afb4:  nop    
0x32f9afb6:  nop    
0x32f9afb8:  nop    
0x32f9afba:  nop    
0x32f9afbc:  nop    
0x32f9afbe:  nop    

EDIT2

好的,在 prepareforsegue 方法中释放位置管理器和 webview 后,它就可以工作了。

最佳答案

您需要在放松之前停止位置管理器。

当您展开时,您实际上是在卸载并释放您正在展开的 ViewController。

但是,因为它是 locationManager 的委托(delegate),所以位置管理器正试图将信息传递给它。

您应该能够通过...解决此问题

[locationManager stopUpdatingLocation];

放松之前。 (可能在prepareForSegue方法中)。

关于ios - 由于位置管理器的原因,展开转场后发生崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28235478/

相关文章:

iOS 8 Swift 阅读列表

ios - 调试器不适用于 Apple Watch Series 3

ios - UISearchBar 上方的 UITableView 背景颜色

iphone - Facebook 提及标签不起作用

ios - Parse.com - 查询自定义类中的关系

ios - 比较复杂的 NSDictionary

ios - 在 Xcode 的单元测试中调用按钮操作

iphone - NSXMLParser 解析方法内存泄漏

iphone - 使用核心数据实体更新表节标题的有效方法?

ios - 如何删除NSCache中的所有缓存?