objective c - beginSheetModalForWindow - the alert window disappear -
what's wrong piece of code implemented in appdelegate ? alert appears shortly on window , disappears. alertdidend callback method never called.
i've tried clean product in xcode 4.6.1 , rebuild it, without success.
- (void) alertdidend:(nsalert *)alert returncode:(nsinteger)returncode contextinfo:(void *)contextinfo { [[alert window] orderout:self]; alertresult = returncode; nslog(@"alertdidend called"); } - (void) showalert { nsalert *savealert = [[nsalert alloc] init]; [savealert setalertstyle:nswarningalertstyle]; [savealert setmessagetext:messagetext]; [savealert setinformativetext:informativetext]; [savealert addbuttonwithtitle:defaultbuttontitle]; [savealert addbuttonwithtitle:secondbuttontitle]; [savealert beginsheetmodalforwindow:[self window] modaldelegate:self didendselector:@selector(alertdidend:returncode:contextinfo:) contextinfo:nil]; }
i answer myself. problem elsewhere in applicationshouldterminate method.
- (nsapplicationterminatereply )applicationshouldterminate:(nsapplication *) sender { if(conditionok) dosomestuff; else // changes not saved { [self showalert]; handlebuttonclicked; } return nsterminatenow; }
in else branch of if statement showalert executed "return nsterminatenow" also. application doesn't wait until button clicked in alert. returns immediately. test response have not yet been posted.
i modify applicationshouldterminate method.
- (nsapplicationterminatereply )applicationshouldterminate:(nsapplication *) sender { if(conditionok) dosomestuff; return nsterminatenow; else { [self showalert]; return nsterminatecancel; } }
the alertdidend callback method test returned button, job , send terminate signal if necessary.
at moment, have not fixed problem know problem.
just question : beginsheetmodalforwindow asynchronous or asynchronous in context of applicationshouldterminate ?
this final version of applicationshouldterminate
- (nsapplicationterminatereply )applicationshouldterminate:(nsapplication *) sender { if([_buttonsave isenabled]) { if(quitmenuterminate) [self majfile]; else { [self showalert]; return nsterminatelater; } } return nsterminatenow; }
in callback method, alertdidend, of beginsheetmodalforwindow, call
[[nsapplication sharedapplication] replytoapplicationshouldterminate:yes];
and ok now.
Comments
Post a Comment