MKMapView在单元格崩溃中

时间:2014-06-10 11:33:53

标签: ios objective-c uitableview 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;
}

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

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。

1 个答案:

答案 0 :(得分:3)

问题在于:

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

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

如果你正在调用cellForRowAtIndexPath:来获取单元格以使其委托无效,则不需要这样做;由于代表很弱,它会被自动清除。