View Controller being sent a message even though it has been deallocated

后端 未结 9 1407
梦毁少年i
梦毁少年i 2020-12-13 11:21

I am not sure if something has changed in the iPhone SDK 3.0 but I am getting the strangest error. I have a view controller hierarchy where I switch between view controllers

9条回答
  •  囚心锁ツ
    2020-12-13 12:01

    If anyone still cares, a simple solution is to create a root view controller + view that never changes.

    Given SomeViewController + SomeView A, and SomeViewController + SomeView B, if you add view A to the window as a subview, then add view B as a subview and remove view A, the app will crash on rotate.

    To prevent the crash, create a generic UIViewController + UIView X, and add view X to the window as a subview. Add and remove views A and B to/from view X, not the window directly. The app will no longer crash.

    Note that it's not enough to just add a view to the window; you must add a view that has a view controller.

提交回复
热议问题