我是可可中的新手。現在我想在iOS中創建一個可選的消息框,但沒有任何按鈕。 Messagebox在NSTimer後自動關閉。我使用下面的代碼,但它總是添加OK按鈕。請給我任何建議。提前致謝。可以在可可中創建無按鈕的NSAlert
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];
KillWindow功能:
-(void) killWindow: (NSTimer *) theTimer
{
NSLog(@"killWindow");
[[alert window] close];
}
當警報關閉,我的應用程序不能點擊任何按鈕或互動?
謝謝,但你能爲我示例代碼? –
[[的NSApplication sharedApplication] beginSheet:scanningPanel modalForWindow:窗口 modalDelegate:自 didEndSelector:@selector(sheetDidEnd:RETURNCODE:contextInfo :) contextInfo:無]; [[NSApplication sharedApplication] runModalForWindow:scanningPanel]; –
我創建了自定義NSpanel,但我不知道如何爲它設置NSTimer。你可以幫我嗎?非常感謝 –