Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 单击按钮等待下一个外部事件_Objective C_Cocoa_User Interface_Modal Dialog - Fatal编程技术网

Objective c 单击按钮等待下一个外部事件

Objective c 单击按钮等待下一个外部事件,objective-c,cocoa,user-interface,modal-dialog,Objective C,Cocoa,User Interface,Modal Dialog,我有一个NSAlert实例,我将其作为模式运行,以便用户在取消某些操作时进行确认。当用户没有响应并且操作完成时,我需要关闭这个模式窗口。为此,我在alert中调用performClick on default按钮。但是我观察到执行点击并没有立即执行,而是等待一些外部事件,比如鼠标移动事件。为什么会这样?除了发布假事件,还有哪些解决方案?以下是您需要做的 Assumption: 1. IBAction is connect to NSButton Which will display the Al

我有一个NSAlert实例,我将其作为模式运行,以便用户在取消某些操作时进行确认。当用户没有响应并且操作完成时,我需要关闭这个模式窗口。为此,我在alert中调用performClick on default按钮。但是我观察到执行点击并没有立即执行,而是等待一些外部事件,比如鼠标移动事件。为什么会这样?除了发布假事件,还有哪些解决方案?

以下是您需要做的

Assumption:
1. IBAction is connect to NSButton Which will display the Alert View after clicking upon it.
2. It will perform Click operation by itself on the Second button of the Alert View.
希望下面的代码将帮助您

- (IBAction)showAlert:(id)sender
{
    //display the alert
    self.myAlert = [NSAlert alertWithMessageText:@"Sample Test" defaultButton:@"OK" alternateButton:@"DO Nothing" otherButton:@"CANCEL" informativeTextWithFormat:@"TEST",nil];
    [self.myAlert beginSheetModalForWindow:[self window]
                         modalDelegate:self
                        didEndSelector:@selector(errorAlertDidEnd:returnCode:contextInfo:)
                           contextInfo:nil];

    NSArray *buttonArray = [self.myAlert buttons];
    NSLog(@"Button Arrays %@",buttonArray);

    //Close by itself without a mouse click by the user
    //Assuming the Default Button as the Second one "Do Nothing
    NSButton *myBtn = [buttonArray objectAtIndex:2];
    [myBtn performClick:self.myAlert];
}


- (void)errorAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
    NSLog(@"TEST");
}

这是你需要做的

Assumption:
1. IBAction is connect to NSButton Which will display the Alert View after clicking upon it.
2. It will perform Click operation by itself on the Second button of the Alert View.
希望下面的代码将帮助您

- (IBAction)showAlert:(id)sender
{
    //display the alert
    self.myAlert = [NSAlert alertWithMessageText:@"Sample Test" defaultButton:@"OK" alternateButton:@"DO Nothing" otherButton:@"CANCEL" informativeTextWithFormat:@"TEST",nil];
    [self.myAlert beginSheetModalForWindow:[self window]
                         modalDelegate:self
                        didEndSelector:@selector(errorAlertDidEnd:returnCode:contextInfo:)
                           contextInfo:nil];

    NSArray *buttonArray = [self.myAlert buttons];
    NSLog(@"Button Arrays %@",buttonArray);

    //Close by itself without a mouse click by the user
    //Assuming the Default Button as the Second one "Do Nothing
    NSButton *myBtn = [buttonArray objectAtIndex:2];
    [myBtn performClick:self.myAlert];
}


- (void)errorAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
    NSLog(@"TEST");
}

要知道单击了哪个按钮,您可以修改mTo要知道单击了哪个按钮,您可以修改方法errorAlterdDend

- (void)errorAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{

   if(returnCode == NSAlertAlternateReturn)
   {
       NSLog(@"TEST Alternate %ld",returnCode);
   }

   if(returnCode == NSAlertDefaultReturn)
   {
       NSLog(@"TEST Default %ld",returnCode);
   }        
    if(returnCode == NSAlertOtherReturn)
    {
        NSLog(@"Test Other %ld",returnCode);
    }    
}

请详细说明“但是点击事件(由performClick生成)本身等待一些外部事件(例如:鼠标移动)–”

要知道点击了哪个按钮,您可以修改mTo要知道点击了哪个按钮,您可以修改方法ErrorAlterdDend

- (void)errorAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{

   if(returnCode == NSAlertAlternateReturn)
   {
       NSLog(@"TEST Alternate %ld",returnCode);
   }

   if(returnCode == NSAlertDefaultReturn)
   {
       NSLog(@"TEST Default %ld",returnCode);
   }        
    if(returnCode == NSAlertOtherReturn)
    {
        NSLog(@"Test Other %ld",returnCode);
    }    
}

请详细说明“但是点击事件(由performClick生成)本身等待一些外部事件(例如:鼠标移动)–”

您需要显示一些有关此操作的代码和详细信息。是一个街区吗?手术?还有别的吗?那么如何调用模式表或窗口?这将帮助人们引导您了解您的选项。您需要显示有关此操作的一些代码和详细信息。是一个街区吗?手术?还有别的吗?那么如何调用模式表或窗口?这将有助于人们引导您了解您的选项。我以类似的方式实现了[myAlert beginSheetModalForWindow…]而不是[myAlert beginSheetModalForWindow…],我使用的是[myAlert runModal],它将给我返回值,指示单击了哪个按钮。但是单击事件(由performClick生成)本身会等待一些外部事件(例如:鼠标移动)来知道单击了哪个按钮。您可以修改方法ErrorAlterdDendi。我们以类似的方式实现了该方法,但我使用的不是[myAlert beginSheetModalForWindow…]而是[myAlert runModal]这将给我返回值,指示单击了哪个按钮。但是单击事件(由performClick生成)本身会等待一些外部事件(例如:鼠标移动)来知道单击了哪个按钮。在performClick之后,您可以修改方法ErrorAlterdIndedData,[myAlert runModal]应该立即返回,但不会立即返回,而是等待下一个外部事件。在performClick之后,使用我建议的方式而不是使用[myAlert runModal],而[myAlert runModal]应该立即返回,但不会立即返回,而是等待下一个外部事件。使用我建议的方式而不是使用[myAlert运行模式]