Mub*_*nga 1 objective-c nswindow
我想向用户寻求确认他想要关闭唯一的窗口以及整个应用程序
到目前为止我有这个:
- (BOOL)windowWillClose:(id)sender{
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"Yes"];
[alert addButtonWithTitle:@"No"];
[alert setMessageText:@"Are you sure you want to quit?"];
[alert setInformativeText:@"Quiting will stop the machine, please make sure it is back to its origin."];
[alert setAlertStyle:NSWarningAlertStyle];
[alert setShowsSuppressionButton:YES];
NSInteger result = [alert runModal];
if ( result == NSAlertFirstButtonReturn ) {
return YES;
} else {
return NO;
}
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
return YES;
}
Run Code Online (Sandbox Code Playgroud)
窗口和应用程序关闭之前有一个ifrt,如果我删除applicationShouldTerminateAfterLastWindowClosed我的窗口关闭,没有任何反应.但是当我把它打开并把这个转发器applicationShouldTerminateAfterLastWindowClosed放在工作中但是我的窗户已经关闭了.
我也尝试过,windowShouldClose但也没用.
我在这里做错了什么想法?
添加一个实现该代理的委托
- (BOOL)windowShouldClose:(id)sender;
Run Code Online (Sandbox Code Playgroud)
委托方法,请参见:https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSWindowDelegate_Protocol/Reference/Reference.html
| 归档时间: |
|
| 查看次数: |
1418 次 |
| 最近记录: |