2014-06-10 52 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