UIButton Error EXC_BAD_ACCESS

I have a user interface button and it works correctly when I clicked. But if I press the button three times, I get an EXc_BAD_ACCESS error. I thought I released something, but could not find a solution. could you help me? Sincerely.

This is the function when I pressed the button. And in dealloc I set them free. When I track, it does not give errors in the function. I got it after the function, but I do not know where the code goes after this function.

- (IBAction) doSomething: (id)sender { [self.answerDict replaceObjectAtIndex:currentPageNumber withObject:@"1"]; [self.b setImage:nil forState:UIControlStateNormal]; [self.c setImage:nil forState:UIControlStateNormal]; [self.d setImage:nil forState:UIControlStateNormal]; [self.e setImage:nil forState:UIControlStateNormal]; UIImage *img = [UIImage imageNamed:@"a.jpg"]; [self.a setImage:img forState:UIControlStateNormal]; [img release]; } 
0
source share
2 answers
 UIImage *img = [UIImage imageNamed:@"a.jpg"]; [self.a setImage:img forState:UIControlStateNormal]; [img release]; 

[img release]; - a problem. You are releasing an object that you do not have. img is automatically freed in this case.

Remove [img release]; and see if there was a failure

+3
source

I suggest you comment on the code line by line, and this way you will understand what the purpose of the BAD_ACCESS error is. On the first day, all the code in doSomething: maybe the main reason is in your button ...

0
source

Source: https://habr.com/ru/post/1394277/


All Articles