开发者

EXC_BAD_ACCESS when removing a view

开发者 https://www.devze.com 2023-02-19 14:07 出处:网络
I have a problem with EXC_BAD_ACCESS. I have a UIWebView that loads a local HTML file and as the app is loading the contents of the view I display a UIView on top of it as a \"splash screen\". Then w

I have a problem with EXC_BAD_ACCESS.

I have a UIWebView that loads a local HTML file and as the app is loading the contents of the view I display a UIView on top of it as a "splash screen". Then when the contents of the UIWebView are loaded I run an animation to fade-out the UIView and remove it from memory.

- (void) webViewDidFinishLoad:(UIWebView *)webView {
        [UIView animateWithDuration:1
                 animations:^{
                      loadingView.alpha = 0.0;
              开发者_运维技巧   }
                 completion:^(BOOL finished){
                     [loadingView removeFromSuperview];
                     [loadingView release];
                 }];
}

The issue is, that when I use the my app fails on the two lines within the completion method. The full error:

Program received signal:  “EXC_BAD_ACCESS”.
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3 (8F190)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).

The loadingView is built through interface builder. Here's the heirarchy:

EXC_BAD_ACCESS when removing a view


Looks like you're releasing the view twice.

Your superview is going to keep a reference to your splash image. That will be released when you removeFromSuperview.

If that is the only reference to the splash image then the next line, the release, is going to over-release and cause the crash. Judging by the code you've given, the solution is to remove the explicit release.

However, if there is more code than you've shown it may be a little more complex, though the same idea.


the exception could be caused by the release when you didn't retain the loadingView before.

If you don't retain (with a retain property for example) you are not allowed to release the view.

But to avoid a leak you should double check if it's okay to simply remove the [loadingView release].

0

精彩评论

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

关注公众号