iOS 7.1 removeFromSuperview crash

后端 未结 9 981
孤街浪徒
孤街浪徒 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:33

    please do the following:

    1- debug the for (UIView *subView in [contentVc subviews]) and check how many times it iterate.

    if it doesn't crash in the first hit you can add this line before you remove the view if (subView.superView != nil)

    else try to make sure that you are not releasing the views twice somewhere else as it's keep showing and will not crash till you remove it from it's superview.

    UPDATE2: i will consider that you are will aware of memory leaks, and that you have good experience in it.

    • whenever you add a subview to a view, this will retain the object by 1 in addition to the original 1, that will equal 2, then directly after adding the subview you have to release it, which will decrement the retain count back to one. here is the trick: you don't have to release the subview or remove it from it's parent view to get rid of the remaining retain count. you can simply remove or release the parent view. get the NSMutableArray As an example.

    • remove the [mainView removeFromSuperview]; from the dealloc: method. you can add it else where like viewWillDisappear: method. dealloc method shouldn't contain anything other than the release calls.

提交回复
热议问题