开发者

How to dismiss a modal view as soon as it's displayed (without user interaction)

开发者 https://www.devze.com 2022-12-21 00:16 出处:网络
I apologize if my question may result trivial or obscure. I am using a view presented modally. In order to achieve a little \'scenographic\' animation effect, based on the value of a parameter, I wish

I apologize if my question may result trivial or obscure. I am using a view presented modally. In order to achieve a little 'scenographic' animation effect, based on the value of a parameter, I wish to reach the following behavior:

If value is 0, the view presented modally stays on display and allows user actions until a back button is pressed (in which case the view is dismissed)

if value is 1, the view is presented modally, then it is开发者_JAVA技巧 dismissed immediately and an alert view appears above the calling view.

Now, I have tried to put the control on the value in the viewDidAppear method, within the modal view controller like this

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:YES];
if (<value> == 1) {
[self dismissModalViewControllerAnimated:YES];
                  }
}

And what I got is: If value is 0 the modal view stays on as planned

If value is 1 the modal view is dismissed as planned, but the application crashes immediately after. The debugger seems to suggest that the problem arose within

-[UIWindowController transitionViewDidComplete: fromView:toView]

And now the question(s): Am I trying to do something seriously illegal/impossible?

If a solution exists, it consists on just moving the control to another method? If yes, which method?

Or the solutions is far more complex?

Thank you


Might be that UIWindowController is mistakenly assuming the view is still visible when the viewDidAppear notification call returns.

Try using performSelector:withObject:afterDelay: with a zero delay - it will call the selected method as soon as possible after control returns to the run loop (and out of the UIWindowController call stack):

- (void) delayedDismissOfModalViewController {
    [self dismissModalViewControllerAnimated:YES];
}

- (void) viewDidAppear: (BOOL) animated {
   [super viewDidAppear:YES];

   if (<value> == 1) {
      [self performSelector: @selector(delayedDismissOfModalViewController)
                 withObject: nil
                 afterDelay: 0];
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消