iOS 7.1 removeFromSuperview crash

后端 未结 9 964
孤街浪徒
孤街浪徒 2021-02-05 13:40

My app didn\'t have any crash until iOS 7.1 came out. Now on any removeFromSuperview method, crash. For example: I got view controllers, and when I

9条回答
  •  孤城傲影
    2021-02-05 14:32

    1.According to the Apple's documentation, calling removeFromSuperview will remove that view from superview and release it automatically.

    So if you are using removeFromSuperview, then you should not call the [removedView release], which will crash your App.

    Refer this screenshot from Apple. 

    enter image description here

    In your dealloc implementation, you are having like so

    - (void) dealloc {
    
        // Removed from Parent view and released.
        [mainView removeFromSuperview];
    
        // no mainView exists in memory , so it crashed the App.
        [mainView release];// Comment this line to avoid the crash
    
        [super dealloc];
    }
    

    2.You should not mute the container that are being enumerated.

    You are having like this,
    
    for (UIView *subView in [contentVc subviews])
         [subView removeFromSuperview];
    

    Instead you can implement the same effect by having this one line from Apple.

    [[contentVc subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
    

提交回复
热议问题