Search code examples
iosobjective-cexc-bad-accessuiactivityviewcontrollerpresentviewcontroller

UIActivityViewController crashes when cancelling on iPhone iOS8


I am showing activityViewController using this line of code from my ViewController

[MyClass showShareMenuWithString:@"test string" sender:self];

This is a declaration of this method inside MyClass

+ (void)showShareMenuWithString:(NSString*)text sender:(id)sender{
    NSArray* array = [NSArray arrayWithObject:[NSString stringWithFormat:@"%@",text]];
    UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:array applicationActivities:nil];

    [sender presentViewController:activityView animated:YES completion:nil];

}

After this, activityView appears on the screen with an ability to select some actions like sending SMS or Email and others. After choosing one of this actions, SMS of Mail controller is presenting on the screen with the prefilled data. But after cancelling this controllers, my app crashes with the EXC_BAD_ACCESS error. It happens randomly, and there's a little chance that this controllers would disappear without crash. Application is iPhone only and array is not a nil.

The app didn't crash on iOS7. It was tested on iPhones with the different iOS 7/8 . Has somebody the same problems? Is there any find out ?


Solution

  • Thanks to @Y.Bonafons

    I didn't set my delegate to nil in the previous controller after pop'ing, that's why it was trying to call it's methods.

    Enabling Zombie Objects helps me a lot.