Search code examples
xcodenstableviewnsalert

Alert window on cancellation row of tableview


I have a NSTableView connected to an arraycontroller, I would like that when the user click on the cancel button of the line, an alert window will appear that asks for confirmation before deleting. How can I do?


Solution

  •     // [_window makeKeyAndOrderFront:nil];
    
    NSAlert *myAlert = [NSAlert alertWithMessageText:@"A message from the bottle"
                                       defaultButton:@"No"
                                     alternateButton:@"Yes"
                                         otherButton:@""
                           informativeTextWithFormat:@"Blah Blah\n\Blah!\nProceed?\n"
                        ];
    
    switch ([myAlert runModal]) {
    
        case 0: // alternateButton
            NSBeep();
            break;
    
        case  1: // defaultButton
            NSBeep();
            break;
    
        default:
            break;
    }