NSAlert组件应用总结 一、引言 在桌面软件开发中,当用户进行非法的操作或有风险的操作时,时长需要弹出警告框来提示用户。在OS X系统上,NSAlert是专门的警告框组件。 二、NSAlert的简单使用 使用警告框最简单的使用方式是提示错误信息,错误信息警告只起到提示用户的作用,其只有一个OK按钮,点击后警告框会关闭。 你也可以对警告框进行自定义设置,例如文本,标题,图标等,示例如下: - (IBAction)alert:(id)sender { NSAlert * alert = [[NSAlert alloc 三、NSAlert属性与方法解析 NSAlert类中的属性和方法解析如下: //直接使用错误信息创建警告框 + (NSAlert *)alertWithError:(NSError *)error; / *)alert; @end 除了上面列出的方法外,NSAlert中还有两个已经弃用的便捷构造和弹出方法,如下: //创建警告框 + (NSAlert *)alertWithMessageText:(nullable
初始化一个 NSAlert 对象,设置其标题,及按钮。 // Create dialog var dialog = NSAlert.alloc().init(); dialog.setMessageText("This a alert view"); dialog.addButtonWithTitle
它的功能是使用NSAlert显示出我们在代码编辑器中选中的文本。 selectedText = [text substringWithRange:selectedRange]; } } - (void) showMessageBox: (id) origin { NSAlert *alert = [[[NSAlert alloc] init] autorelease]; [alert setMessageText: selectedText]; [alert
我们写的导入方法,需要提示用户错误信息,我们用NSAlert提示用户。新建一个类OAlertMessage。 /// 提示错误信息 /// /// - Parameter message: 错误信息的文本 class func alert(message:String) { let alert = NSAlert
///< 用来知道要删除那个文件 关于 NSAlert 对于弹出框我们可以使用 NSAlert控件 参考资料: 苹果小白的学习之路--NSAlert的两种使用方法。 self.fileName, let window = NSApplication.shared().keyWindow else { return } let alert = NSAlert self.fileName, let window = NSApplication.shared().keyWindow else { return } let alert = NSAlert
我个人感觉,RuntimeException 跟OC 中的 断言(NSAlert) 有点像哦。
{ let dataString = try String(contentsOfFile: fileName) } catch _ { let alert = NSAlert