0

Just converted a project to ARC and am now getting a EXEC_BAD_ACCESS after I dismiss a UIActionsheet, it was previously working and I am unsure if this is even ARC related. Zombies is enabled but showing me nothing and I tried instuments and it also gave me nothing.

This is presented in a modal view controller, case 0, the quit button works fine but the other two give me the bad access error.

This is my first conversion to ARC, am I missing something here?

Action sheet Creation:

-(IBAction)quitPressed:(id)sender {
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Quit This Game?"    delegate:self cancelButtonTitle:@"Keep Playing" destructiveButtonTitle:@"Quit" otherButtonTitles:@"Quit and Reveal Answers",nil];
    [sheet showInView:self.view];

}

Action sheet delegate:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    switch (buttonIndex) {
        case 0:  //quit
            [self dismissViewControllerAnimated:NO completion:^{
            [self.delegate quitGame];
        }];
        break;
        case 1:  //quit and reveal
            NSLog(@"reveal");
            break;
        case 2: //cancel
            NSLog(@"cancel"); 
            break;
        default:
        break;
    }

}

tassinari
  • 2,313
  • 2
  • 24
  • 32

3 Answers3

0

If your delegate is declared strong in the .h file. Have you initialized the self.delegate at least once in the .m file(preferably viewDidLoad) using

self.delegate = [[UIApplication sharedApplication] delegate];

Vimal Venugopalan
  • 4,091
  • 3
  • 16
  • 25
0

Delegates should be weak or assign (__weak / __unsafe_unretained for ivars) to avoid any retain cycles.

Hold a reference to the sheet that you create. You can clear that reference once the sheet was closed.

florianbuerger
  • 422
  • 2
  • 9
0

Thanks everyone for the help. I found the problem when I ran the project under xcode 4.5. It gave a compile error: switch case is protected in scope

I wasn't getting that error in xcode 4.3

It was solved in this thread When converting a project to use ARC what does "switch case is in protected scope" mean?

I wrapped each case in curly brackets and the problem has been fixed.

Community
  • 1
  • 1
tassinari
  • 2,313
  • 2
  • 24
  • 32
  • Ah. Xcode 4.3's ARC wasn't very mature yet. If you plan on going back, that's probably something you should mention in future questions. – Steven Fisher Sep 15 '12 at 01:25