Domanda

I use the state restoration offered by the SDK.

I load all my view controllers from the storyboard. The initial view controller shows another view controller modally. Both have a restoration identifier.

The restoration works fine BUT: When I am in the modally presented view controller and press home (save the state). Then reopen the app and state restoration starts the following happens:

For a split second I see the initial view controller and then the screen changes to the modally presented controller which I actually want to see.

Why is this happening? The snapshot in the caches directory does show the correct screen (from the presented view controller).

You can reproduce the issue with this project. Add a breakpoint in the initial view controller's viewDidAppear method and when restoring state, you will see initial view controller's view in the screen and in view hierarchy:

(lldb) po [[UIWindow keyWindow] recursiveDescription]
<UIWindow: 0x155607f0; frame = (0 0; 320 480); autoresize = W+H; gestureRecognizers = <NSArray: 0x15560d20>; layer = <UIWindowLayer: 0x1555f4f0>>
   | <UIView: 0x15542ad0; frame = (0 0; 320 480); autoresize = RM+BM; layer = <CALayer: 0x15542a70>>
   |    | <UIButton: 0x155432d0; frame = (137 269; 46 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x15543b30>>
   |    |    | <UIButtonLabel: 0x15663dd0; frame = (0 6; 46 18); text = 'Button'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x1566da20>>
   |    | <_UILayoutGuide: 0x15542b60; frame = (0 0; 0 20); hidden = YES; layer = <CALayer: 0x15542fe0>>
   |    | <_UILayoutGuide: 0x15541060; frame = (0 480; 0 0); hidden = YES; layer = <CALayer: 0x155410d0>>

If you check view controller hierarchy, modally presented view controller is not in initial view controller presented property:

(lldb) po [[[UIWindow keyWindow] rootViewController] presentedViewController]
 nil

and breakpoint is after (theoretically) state restoration. But later it will be set correctly.

È stato utile?

Soluzione

That issue seems to happen when working with storyboards where you let the framework call [window makeKeyAndVisible] for you and it is happening after restoration.

If you add next line to application:willFinishLaunchingWithOptions:

[self.window makeKeyAndVisible];

it will fix it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top