8

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.

Profile --> Zombies

Xavi Valero
  • 2,047
  • 7
  • 42
  • 80
  • `UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc]initWithTitle:NSLocalizedString(@"contacts",@"Contacts") style:UIBarButtonItemStyleBordered target:self action:@selector(cancel:)];` This is the reason behind crash. Have you used `UIBarButtonItemStylePlain` ? – Devel Dec 19 '13 at 17:12
  • Can you set an Exception breakpoint to narrow it down to the exact line of code that triggers the crash? – Jai Govindani Dec 19 '13 at 17:15
  • @JaiGovindani It doesn't seem to crash in code. – Xavi Valero Dec 19 '13 at 17:18
  • You mean it doesn't crash when you're running in a simulator? How about running it on a device but connected to Xcode? – Jai Govindani Dec 19 '13 at 17:21
  • Exactly. It doesn't crash in simulator. Only in device it cranes. – Xavi Valero Dec 19 '13 at 17:24
  • The Exception breakpoint should still work when debugging on device. Or do you mean that it doesn't crash when debugging on a device using Xcode? – Jai Govindani Dec 19 '13 at 17:37
  • @JaiGovindani It crashes. But not in any written line of code. – Xavi Valero Dec 19 '13 at 17:58
  • Just to be clear, you've set an Exception breakpoint? This should stop execution in the line of code just before the exception is raised. So even with an Exception breakpoint set (and turned on) it crashes without stopping on any particular line of code? – Jai Govindani Dec 19 '13 at 18:00
  • Yes. I have put an exception break point and still I cant find out the line of code where the app crashes. – Xavi Valero Dec 19 '13 at 18:01
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/43537/discussion-between-xavi-valero-and-jai-govindani) – Xavi Valero Dec 19 '13 at 18:02
  • You need to show us the code where you invoke the map view, as that is where the crash occurs. Is it in one of those bar button methods or elsewhere? Can you also show how _this_ navController is invoked and dismissed, as the crash is caused when you send a message to a dealloc'd controller. My guess is that you are invoking or dismissing something incorrectly (either the nav controller or the map view), but without more code I could not be sure. Can you post the project up somewhere? – foundry Dec 28 '13 at 11:20
  • In didLoad I just make a MKMapView object and loads it. And it doesn't crash on a particular line of code. But if I remove/comment the line of code where I load the mapview, it doesn't crash. I also tried removing/commenting the code and load mapview from storyboard and its the same result. The crash is exactly the same. Currently I am not in a position to post the code here, but will do that ASAP. – Xavi Valero Dec 28 '13 at 14:55
  • See http://stackoverflow.com/questions/20146979/app-crash-on-use-of-peoplepicker-but-not-in-same-view. The question (not the accepted answer) contains a link to this workaround: https://discussions.apple.com/thread/5498630?start=15&tstart=0 –  Feb 13 '14 at 21:20

2 Answers2

4

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 :)

LeChatNoir
  • 1,128
  • 10
  • 9
  • 1
    Also see http://stackoverflow.com/questions/20146979/app-crash-on-use-of-peoplepicker-but-not-in-same-view. That question (not the accepted answer) contains a link to this other workaround: https://discussions.apple.com/thread/5498630?start=15&tstart=0 –  Feb 13 '14 at 21:22
0

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; }

JohnWick
  • 241
  • 2
  • 13