views:

307

answers:

3

I'm displaying a modal uiviewcontroller in the normal fashion:

[self.navigationController presentModalViewController:self.lvc animated:YES];
//do stuff

and later on...

[self.navigationController dismissModalViewControllerAnimated:FALSE];

The problem is that //do stuff is too fast, and the dismiss call happens before the presentation call animation completes, which has the net effect of not dismissing the view at all. if i set the animation parameter to false, everything works, every time, or if //do stuff takes longer than the animation...

what to do? sleep? (ick), cancel the transition animation somehow?

not enough info? here's some more:

the point is, sometimes the worker thread finishes before the original modalviewcontroller animation completes, which causes problems when dismissmodalviewcontroller is called. In summary, if you call dismiss before the present animation completes, you cannot actually dismiss it. I'm filing a bug w/ apple atm.

And here's the proof testcase:


#import "ModalbugsViewController.h"

@implementation modalbugsViewController
@synthesize modal;
-(void)dismisser {
    [self dismissModalViewControllerAnimated:TRUE];
}
-(void) sleeper:(NSNumber *) t{
    [NSThread sleepForTimeInterval:[t floatValue]];
    [self performSelectorOnMainThread:@selector(dismisser) withObject:NULL waitUntilDone:TRUE];
}
-(IBAction) shortClick:(id)sender {
    [self presentModalViewController:self.modal animated:YES];
    [NSThread detachNewThreadSelector:@selector(sleeper:) toTarget:self withObject:[NSNumber numberWithFloat:0.1f]];

}
-(IBAction) longClick:(id)sender {
    [self presentModalViewController:self.modal animated:YES];
    [NSThread detachNewThreadSelector:@selector(sleeper:) toTarget:self withObject:[NSNumber numberWithFloat:5.0f]];
}


- (void)dealloc {
    [self.modal release];
    [super dealloc];
}

@end

A: 

I prefer to do smth that can take much time in the separate thread. Then you can notify main thread(for example, you can set caller as the delegate and send a message after your calculation, or url request, or smth else has been ended) and dismiss your modal view controller there. I use performSelector:withObject:afterDelay: method if I don't know time of the calculation and want to show animation correctly.

Morion
you are misunderstanding the problem.
McClain Looney
according to the updated info. why cannot you just dismiss your modal viewController with, for example, 1 second delay? I think it will be long enough.
Morion
yes, there are numerous, irritating workarounds. looks like it's just another sdk bug.
McClain Looney
A: 

Are you using the modal dialog to show information about the stuff you are doing? i.e. is it being used as a Please Wait... If so when you're probably better just showing a please wait dialog over the top of your current view.

lyonanderson
sure, i'd maybe be better off, and it may be easier, but that's not what i want to do.
McClain Looney
A: 

Looks like it's a bug. delay your dismiss long enough with nsthread, or engage in other stupidity to work-around.

McClain Looney