tags:

views:

17

answers:

1

I have the following code where I display a view controller within a navigation controller. Just for the test I display it for 3 seconds and then dismiss it. What is happening is that it disappearing - and then reappearing after a second or so. What am I doign wrong?

- (void) test
{
    [myNavCtrl dismissModalViewControllerAnimated:YES];
}

- (void) viewDidAppear:(BOOL)animated
{
    MyViewController *ctrl = [[MyViewController alloc] init];
    [ctrl setDelegate:self];
    myNavCtrl = [[UINavigationController alloc] initWithRootViewController:ctrl];
    [myNavCtrl setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
    [self presentModalViewController:myNavCtrl animated:NO];
    [ctrl release];
    [myNavCtrl release];

    [self performSelector:@selector(test) withObject:nil afterDelay:3];
}
A: 

The viewWillAppear method is called every time the controller's view appears so you've created a loop. The view appears, it calls the modal view which covers the calling view. When the modal view disappears, the calling view controller's viewWillAppear gets called again. Lather, rinse, repeat.

TechZen