相信很多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);