Do not press the NSAlert button while pressing the button

I am showing NSAlert with a custom view and three buttons. The user view has two text fields and allows the user to log in.

NSAlert with a similar design has appeared in the Mac App Store. When the user clicks the login button, NSAlert does not reject (until the credentials are verified). How does Apple support alerts?

+4
source share
1 answer

Get NSButton that you want to behave differently. Change its purpose and action. (To go to the original goal / action, save them before changing them.)

 NSAlert *alert = ...; NSButton *button = [[alert buttons] objectAtIndex:...]; id oldTarget = [button target]; SEL oldAction = [button action]; [button setTarget:self]; [button setAction:@selector(verifyCredentials:)]; 

Alternatively, you can create an alert as a custom window controller and XIB (as Apple did in the case of the App Store). In this case, you have small-scale control over the behavior of the buttons.

+8
source

All Articles