aneuryzm
aneuryzm

Reputation: 64864

How to open a NSAlert in awakeFromNib? (taking care of the window animation)

I get a problem with a NSAlert that is created in -awakeFromNib method.

The xib window animation takes some time, and the alert is crated and added to the app too early (so it is detached from the window).

If instead I delay the method call everything works fine, but I guess that's not the correct way to implement it. How should I code it instead?

- (void) awakeFromNib
{
       ...
      [self performSelector:@selector(showAlertMethod) withObject:nil afterDelay:0.01];
}

Upvotes: 1

Views: 143

Answers (1)

Rudi Angela
Rudi Angela

Reputation: 1483

To ensure the method is executed when the main thread is done with its current tasks you can dispatch the method call to the main queue:

dispatch_async(dispatch_get_main_queue(), ^ {
    [self showAlertMethod];
});

Upvotes: 2

Related Questions