相关疑难解决方法(0)

使用Swift创建NSAlert

我有在Objective-C中创建和NSAlert的代码,但我现在想在Swift中创建它.

警报是确认用户想要删除文档.

我希望"删除"按钮然后运行删除功能和"取消"按钮只是为了解除警报.

我怎么能在Swift中写这个?

NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert addButtonWithTitle:@"Delete"];
[alert addButtonWithTitle:@"Cancel"];
[alert setMessageText:@"Delete the document?"];
[alert setInformativeText:@"Are you sure you would like to delete the document?"];
[alert setAlertStyle:NSWarningAlertStyle];
[alert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
Run Code Online (Sandbox Code Playgroud)

cocoa nsalert swift

40
推荐指数
4
解决办法
3万
查看次数

标签 统计

cocoa ×1

nsalert ×1

swift ×1