macOS开发之警告视图
发布日期:2021-06-29 11:52:50 浏览次数:3 分类:技术文章

本文共 1217 字,大约阅读时间需要 4 分钟。

macOS开发中警告视图有两种显示方式:

对话框模式的告警窗口

//对话框模式的告警窗口    NSInteger choice = NSRunAlertPanel(@"title", @"Message", @"@Default", @"Alternate", @"Other");    NSLog(@"Log_choice:%ld", (long)choice);    if (choice == NSAlertDefaultReturn) {
//1 }else if(choice == NSAlertAlternateReturn) {
//0 }else if(choice == NSAlertOtherReturn) {
//-1 }else if(choice == NSAlertErrorReturn) {
//-2 }else { }

sheet模式运行的警告窗口

//sheet模式运行的警告窗口    NSAlert *alert = [NSAlert alertWithMessageText:@"Message" defaultButton:@"Default" alternateButton:@"alternameButton" otherButton:@"otherButton" informativeTextWithFormat:@"%@", @"this is alert message"];//    [alert beginSheetModalForWindow:[NSApp mainWindow] modalDelegate:self didEndSelector:@selector(alertEnded:code:context:) contextInfo:NULL];    [alert beginSheetModalForWindow:[NSApp mainWindow] completionHandler:^(NSModalResponse returnCode) {        if (returnCode == NSModalResponseOK) {            NSLog(@"Log_222");        }else if(returnCode == NSModalResponseCancel) {            NSLog(@"Log_333");        }    }];

若使用代理方式,则需要添加代理方法如下:

- (void)alertEnded:(NSAlert *)alert code:(NSInteger)choice context:(void *)v {    if (choice == NSAlertDefaultReturn) {    }}

转载地址:https://blog.csdn.net/zzl819954692/article/details/80974673 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:cast of NSInteger (aka int) to id is disallowed withARC
下一篇:macOS开发中用TagLib获取、修改音频文件信息

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月28日 14时34分18秒