开发者

iOS5 throws EXC_BAD_ACCESS error

开发者 https://www.devze.com 2023-04-11 16:45 出处:网络
We have Objective-C code that works fine in all other versions of iOS but is now failing with iOS5.Below is the section of code failing, it stops on the setSelectedCell line with \'EXC_BA开发者_StackO

We have Objective-C code that works fine in all other versions of iOS but is now failing with iOS5. Below is the section of code failing, it stops on the setSelectedCell line with 'EXC_BA开发者_StackOverflow中文版D_ACCESS'

-(void)viewWillAppear:(BOOL)animated {
    Application *app = [Application sharedManager];
    [app setSelectedCell:nil deselectedCell:[menuItemTableView 
                      cellForRowAtIndexPath:currentIndexPath]];
}

As anyone come across this error? Any ideas how to fix?

Thanks!


Probably, your bug was there for past versions and now is just being detected better in iOS5. The most important thing to understand about EXC_BAD_ACCESS is that the line where it is detected may or may not have anything to do with the code that is causing it.

I wrote it about it extensively here:

http://loufranco.com/blog/files/Understanding-EXC_BAD_ACCESS.html

There are debugging tips there as well, but to summarize

  1. Do a Build and Analyze -- fix everything you see
  2. If you think you are over-releasing, try to turn on zombies
  3. Debug Malloc might make the error happen closer to the cause

To reiterate -- just because you don't get the EXC_BAD_ACCESS doesn't mean you don't have a memory-crashing bug -- it just means that it wasn't detected by the virtual memory/memory paging system.


I can't tell from the little code you've pasted, but it could be an issue with Automatic Reference Counting (A.R.C.)

http://developer.apple.com/technologies/ios5/

Try switching this off in the build settings.


If menuItemTable has been released but not set to nil, that would crash the app and give you an EXC_BAD_ACCESS as you are sending a message to something that doesn't exist and isn't nil.

0

精彩评论

暂无评论...
验证码 换一张
取 消