2014-06-10 57 views
1

我有一个自定义单元格中的地图视图。 我创建的单元格,委托这样的:MKMapView在单元崩溃中

if (indexPath.section == 0) { 
    //mapview 
    static NSString *CellIdentifier = @"MapCell"; 
    MapCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil]; 
     cell = [topLevelObjects objectAtIndex:0]; 
    } 

    // Map delegate 
    cell.mapView.delegate = self; 
} 

它工作正常,但有时crashlytics,出现以下日志崩溃:

Thread : Crashed: com.apple.main-thread      0 libobjc.A.dylib    
0x389478f8 _objc_trap() + 18446744073709552000    1 libobjc.A.dylib  
0x3894795d _objc_inform          2 libobjc.A.dylib    
0x389563cb weak_register_no_lock + 182      3 libobjc.A.dylib    
0x389566ff objc_storeWeak + 110        4 MapKit       
0x2f3d6fdd -[MKMapView(MKNonARC) setDelegate:] + 160  5 PTV Truck  
0x0013e63f -[DetailParkingViewController tableView:cellForRowAtIndexPath:] (DetailParkingViewController.m:771) 6 UIKit 
0x30b15199 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 408   7 UIKit 
0x30abc3fb -[UITableView _updateVisibleCellsNow:] + 1802 8 UIKit 
0x30b00caf -[UITableView cellForRowAtIndexPath:] + 142  9 PTV Truck 
0x00147d7b -[DetailParkingViewController dealloc] (DetailParkingViewController.m:1867)       10 libsystem_blocks.dylib   
0x38e62ac5 _Block_release + 216        11 libdispatch.dylib    
0x38e30d3f _dispatch_client_callout + 22     12 libdispatch.dylib   
0x38e336c3 _dispatch_main_queue_callback_4CF + 278   13 CoreFoundation 
0x2e17d679 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8 14 CoreFoundation 
0x2e17bf45 __CFRunLoopRun + 1308       15 CoreFoundation 
0x2e0e67a9 CFRunLoopRunSpecific + 524      16 CoreFoundation 
0x2e0e658b CFRunLoopRunInMode + 106       17 GraphicsServices 
0x330536d3 GSEventRunModal + 138       18 UIKit 
0x30a45891 UIApplicationMain + 1136       19 PTV Truck 
0x000b7037 main (main.m:16) 

我不知道为什么崩溃有时会发生的一些用户... Crashlytics说它发生在cellForRowAtIndexPath中。

回答

3

的问题是在这里:

0x30b00caf -[UITableView cellForRowAtIndexPath:] + 142 9 PTV Truck 
0x00147d7b -[DetailParkingViewController dealloc] (DetailParkingViewController.m:1867) 10 libsystem_blocks.dylib 

它看起来像你打电话的cellForRowAtIndexPath:在您的视图控制器的dealloc方法。通常,从那里调用任何东西都是危险的,但是这个特殊问题是因为不允许将弱引用(地图视图的委托)设置为释放对象。我会停止从你的dealloc调用这个方法。

如果您调用cellForRowAtIndexPath:获取单元格以删除其委托,则无需执行此操作;由于代表软弱,它会自动清除。

+0

感谢您的建议! – vburojevic