Dr.*_*eon 1 cocoa modal-dialog objective-c nsalert
我想显示一张工作表,当用户点击"确定"时,显示另一张工作表.
然而,点击"确定"的那一刻整个设计变得一团糟,好像第一张警报表没有足够的时间消失.
这是我用于表单的代码:
#define CONFIRM_ALERT(X,Y,Z,W,V) \
NSAlert* confirmAlert = [NSAlert alertWithMessageText:X \
defaultButton:@"OK" \
alternateButton:@"Cancel" \
otherButton:nil \
informativeTextWithFormat:Y]; \
[confirmAlert beginSheetModalForWindow:Z \
modalDelegate:self \
didEndSelector:W \
contextInfo:V];
#define INFO_ALERT(X,Y,Z) \
NSAlert *infoAlert = [[NSAlert alloc] init]; \
[infoAlert addButtonWithTitle:@"OK"]; \
[infoAlert setMessageText:X]; \
[infoAlert setInformativeText:Y];\
[infoAlert setAlertStyle:NSInformationalAlertStyle]; \
[infoAlert beginSheetModalForWindow:Z modalDelegate:self didEndSelector:nil contextInfo:nil];
Run Code Online (Sandbox Code Playgroud)
以及我如何使用它:
- (void)doSth
{
CONFIRM_ALERT(@"New Action",
@"Are you sure you want to proceed?",
[self window],
@selector(confirm:code:context:),
nil);
}
- (void)confirm:(NSAlert*)alert code:(int)choice context:(void *)filename
{
if (choice == NSAlertDefaultReturn)
{
INFO_ALERT(@"Success :-)",
@"The Action has been successfully completed.",
[self window]);
}
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?我究竟做错了什么?
它应该只是放在[[alert window] orderOut:nil]第一个警报结束方法的顶部.这实际上记录在参考文献中-[NSAlert beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:\].