我正在尝试编写一个 NSAlert,当某些 NSTextFields 为空时出现。我有 3 个 NSTextField,我想要一个 NSAlert 来显示列表中哪个 TextField 为空。我可以为一个文本字段执行此操作,但我如何编码空的 NSTextFields 出现在 Alert 中?如果 Altert 中的一个 Textfield 为空,则应显示“TextField 1 is empty”。如果字段 1 和 2 为空,则应显示“TextField 1 为空”和第二行“TextField 2 为空”。
这是我的代码:
if ([[TextField1 stringValue] length] == 0) {
NSAlert* alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:@"Error"];
[alert setInformativeText:@"TextField 1 is empty"];
[alert beginSheetModalForWindow:[self.view window] completionHandler:^(NSInteger result) {
NSLog(@"Success");
}];
}