iOS 7.1 removeFromSuperview crash

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

    sometimes crash for:

    [myactualviewcontroller.view removeFromSuperview];
    

    You shouldn't add or remove a controllers' view from a view hierarchy manually but rather rely in UIWindow's rootViewController, push your controller to a UINavigationController, etc., to get the system to add the view to private underlying superviews. Unless your creating a Custom Container View Controller, which I guess you aren't.

    If you just want to handle views manually don't use view controllers as they won't get retained by the system and they won't get any rotation messages, etc. So using a view controller is pointless in that case anyway.

    As for subview memory handling, subviews are retained by their superview, so as long as you don't keep a strong reference, you don't need to release subviews, just remove a common superview.

    Again, if you properly use view controllers just releasing the controller will get rid of all views.

    Finally, you should start using ARC.

提交回复
热议问题