Jos*_*iel 0 macos cocoa objective-c
我是Cocoa的新手.现在我想在iOS中创建一个消息框同样没有任何按钮.NSTimer后消息框自动关闭.我使用下面的代码,但它总是添加确定按钮.请给我任何建议.提前致谢.
alert = [[[NSAlert alloc] init] autorelease];
// [alert addButtonWithTitle: @"OK"];
[alert setMessageText: @"Attention!!! This a critical Alert."];
[alert setInformativeText:@"Scanning..."];
[alert setAlertStyle: NSInformationalAlertStyle];
NSTimer *myTimer = [NSTimer timerWithTimeInterval: 17.0
target:self
selector: @selector(killWindow:) userInfo:nil
repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:myTimer forMode:NSModalPanelRunLoopMode];
int choice = 0;
choice = [alert runModal];
if(choice != 0)
[myTimer invalidate];
Run Code Online (Sandbox Code Playgroud)
KillWindow功能:
-(void) killWindow: (NSTimer *) theTimer
{
NSLog(@"killWindow");
[[alert window] close];
}
Run Code Online (Sandbox Code Playgroud)
当警报关闭时,我的应用程序无法单击任何按钮或交互?
也许在2013年答案是否定的.但是,在当前的SDK(Xcode 7.0 with OS X 10.11)中,您可以通过addButtonWithTitle("")添加"",然后按钮将不会显示.
| 归档时间: |
|
| 查看次数: |
3224 次 |
| 最近记录: |