The app I am working on is a trivia quiz. If you get the answer wrong, it shows you the correct answer.
The correct answer is stored in a string like so:
correctAnswer = [NSString stringWithFormat:@"1/100"];
When it's time to show the answer to the user, I set the label's text to the correct answer:
whatsRight.text = correctAnswer;
This works 99% of the time. BUT - occasionally I get an EXC_BAD_ACCESS terminating the app and the correctAnswer string is said to be "out of scope." This seems to always happen on the same question in my app - the one shown above where the correctAnswer is 1/100. It doesn't always crash the app with EXC_BAD_ACCESS though. Lots of times it works perfectly fine, displays the answer on screen, and the 开发者_高级运维app continues on. Occasionally it crashes.
Any help would be greatly appreciated! Thanks!
Try retaining correctAnswer via [correctAnswer retain]. My thought is that the correctAnswer object may be an autorelease object and since your not retaining it, it's getting released.
精彩评论