简体   繁体   中英

Crash when loading MKMapView

I am having a peculiar crash when loading MKMapView . The pattern of occurrence is when I open ABPeoplePickerNavigationController in one view, which in turn triggers the UINavigationController delegate method

And after saving/without saving I move to another view--its working fine. Next view--its working fine. But when I enter the view with MKMapView , it crashes.

No other views are having any problem. Only the view which loads MKMapView crashes with the following log

*** -[UINavigationBar barStyle]: message sent to deallocated instance

I have commented the part in the code which loads the mapview and then it works fine. So it seems that my navigation bar is deallocated somewhere, when the mapview loads. But what I cant understand is that, no other view in the app has any problem, only the one with mapview crashes. I have tried different patterns of testing and made sure that none of the other views are having any problems.

The app doesn't crash in simulator. It crashes only on device. Why is this issue only in the view which loads mapview and in no other views.

I tried profiling to analyze my problem. Here is what I found, but its not much helpful.

简介->僵尸

I have had the same problem.

It's a leak issue on the ABPeoplePickerNavigationController. You have to ensure it won't be deallocated.

I'm declaring it as a strong property to ensure it won't be deallocated and it works fine :)

Well, there is also a bit more simple solution to this. The actual problem is in using ABPeoplePickerNavigationController as a singleton object, setting its delegate to a view controller and then dismissing the view controller. So, in my case the solution that worked is this one:

  • (void)peoplePickerNavigationControllerDidCancel: (ABPeoplePickerNavigationController *)peoplePicker { peoplePicker.peoplePickerDelegate = nil; // clear delegate prior to dismissing self [self.navigationController dismissViewControllerAnimated:YES completion:nil]; }

  • (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier { [self displayPerson:person]; peoplePicker.peoplePickerDelegate = nil; // clear delegate prior to dismissing self [self.navigationController dismissViewControllerAnimated:YES completion:nil]; return NO; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM