Xcode Cocoa程序MessageBox 弹框

来源:互联网 发布:mysql 最多从库 编辑:程序博客网 时间:2024/06/15 23:12

相信很多Windows程序员都习惯MessageBox弹框提示, 在MacOS下也有类似MessageBox这种弹框提示方法

第一种方法

    //其他的各种弹框类型    NSAlert *alert = [[NSAlert alloc] init];    //[alert addButtonWithTitle:@"OK"];    //[alert addButtonWithTitle:@"Cancel"];    [alert setMessageText:@"test?"];    //[alert setInformativeText:@"Deleted records cannot be restored."];    //[alert setAlertStyle:NSWarningAlertStyle];    // [alert setHelpAnchor:@"ddd"];    // [alert setInformativeText:@"asdfa"];    // [alert setMessageText:strMsg];    /*     [alert beginSheetModalForWindow:_window     modalDelegate:self     didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)     contextInfo:nil];       */      [alert runModal];

第二种方法

    CFOptionFlags  result;    NSString *strMsg = [NSString stringWithFormat:@"%i", 234];    CFStringRef* msg_ref;        CFUserNotificationDisplayAlert(0,                                   kCFUserNotificationNoDefaultButtonFlag,                                   NULL, NULL, NULL,                                   CFSTR("Title"),                                   CFSTR("Message"),                                   NULL, NULL, NULL, &result);


0 0