views:

141

answers:

1

Hello everybody, 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 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

+3  A: 

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];
   }
}
tedge
Cool! Tried, it seems to perfectly work, and it taught me something new... I am impressed, thank you very much.