mapkit addAnnotations crashes

戏子无情 提交于 2020-01-04 05:45:11

问题


I have a UITabBarController and a "Map" tab on it. The Map tab is associated with my custom UIViewController and it has a MKMapView on it. When I'm currently selecting another tab, and when I do tap on the Map tab, iPhone4 with iOS4.3.1 crashes with a crash log like this:

What can I do to prevent this crash? What's wrong with my code?

  0   MapKit                        0x3501fc20 _contains(objc_object*, MKQuadTrieNode*) + 16
  1   MapKit                        0x3501fc00 -[MKQuadTrie contains:] + 12
  2   MapKit                        0x3501f9f2 -[MKAnnotationContainerView addAnnotation:] + 218
  3   MapKit                        0x3501f8e6 -[MKAnnotationContainerView addAnnotations:] + 102
  4   MapKit                        0x3501f856 -[MKMapView addAnnotations:] + 42

  5   MyApp                         0x000075d6 0x1000 + 26070

  6   UIKit                         0x3559ff08 -[UIViewController view] + 104
  7   UIKit                         0x355dd1d4 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 60
  8   UIKit                         0x355dd186 -[UITabBarController transitionFromViewController:toViewController:] + 26
  9   UIKit                         0x355dca2c -[UITabBarController _setSelectedViewController:] + 180
  10  UIKit                         0x35661ce4 -[UITabBarController setSelectedViewController:] + 8
  11  UIKit                         0x35661be0 -[UITabBarController _tabBarItemClicked:] + 220
  12  CoreFoundation                0x3593656a -[NSObject(NSObject) performSelector:withObject:withObject:] + 18
  13  UIKit                         0x35585ec2 -[UIApplication sendAction:to:from:forEvent:] + 78
  14  UIKit                         0x35585e62 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 26
  15  UIKit                         0x35661a84 -[UITabBar _sendAction:withEvent:] + 264
  16  CoreFoundation                0x3593656a -[NSObject(NSObject) performSelector:withObject:withObject:] + 18
  17  UIKit                         0x35585ec2 -[UIApplication sendAction:to:from:forEvent:] + 78
  18  UIKit                         0x35585e62 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 26
  19  UIKit                         0x35585e34 -[UIControl sendAction:to:forEvent:] + 32
  20  UIKit                         0x35585b86 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 350
  21  UIKit                         0x355bfbd2 -[UIControl sendActionsForControlEvents:] + 10
  22  UIKit                         0x3566180e -[UITabBar(Static) _buttonUp:] + 74
  23  CoreFoundation                0x3593656a -[NSObject(NSObject) performSelector:withObject:withObject:] + 18
  24  UIKit                         0x35585ec2 -[UIApplication sendAction:to:from:forEvent:] + 78
  25  UIKit                         0x35585e62 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 26
  26  UIKit                         0x35585e34 -[UIControl sendAction:to:forEvent:] + 32
  27  UIKit                         0x35585b86 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 350
  28  UIKit                         0x3558641c -[UIControl touchesEnded:withEvent:] + 336
  29  UIKit                         0x35584bee -[UIWindow _sendTouchesForEvent:] + 362
  30  UIKit                         0x35584568 -[UIWindow sendEvent:] + 256
  31  UIKit                         0x3556d30c -[UIApplication sendEvent:] + 292
  32  UIKit                         0x3556cc4c _UIApplicationHandleEvent + 5084

My custom UIViewController does this on viewDidLoad:

- (void) viewDidLoad {
    [super viewDidLoad];

    self.mapView.showsUserLocation = NO;

    // some [[NSNotificationCenter defaultCenter] addObserver....] snipped

    [ self.mapView addAnnotations: **my annotations** ];
}

I think the 5th line in the stack trace is viewDidLoad, so the crash must be(I think..) due to my annotations. I had 300-400 annotations when it crashed. My annotations has a coordinate accessor like this:

- (CLLocationCoordinate2D)coordinate {
    CLLocationCoordinate2D  coordinate_;
    coordinate_.latitude  = [ self.lat doubleValue ];
    coordinate_.longitude = [ self.lng doubleValue ];
    return coordinate_;
}

Where self.lat,lng is defined as:

@property (nonatomic, retain) NSNumber* lat;
@property (nonatomic, retain) NSNumber* lng;

It's an app already on AppStore and I don't know how to reproduce the crash, it just doesn't crash now, so all I have is the crash log and my source code. Any suggestions?

Thanks in advance.

来源:https://stackoverflow.com/questions/5687451/mapkit-addannotations-crashes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!