How to create custom NSAlert Sheet Method with the Completion Handler paradigm

Miek

I have used this simple general method for a While and it works fine for App Based dialogs, however I would like the same functionality in a sheet style dialog and I am having a hard time getting one together.

According to the docs as I understand them, the only non deprecated approach from OS10.9 and beyond is to use the NSAlert class with the completion handler process. It seems to make it almost impossible to return a Bool from the general purpose method.

My Code:

-(BOOL)confirm :(NSString*)questionTitle withMoreInfo:(NSString*)addInfo andTheActionButtonTitle:(NSString*)actionType{
    BOOL confirmFlag = NO;

    NSAlert *alert = [NSAlert alertWithMessageText: questionTitle
                                 defaultButton:actionType
                               alternateButton:@"Cancel"
                                   otherButton:nil
                     informativeTextWithFormat:@"%@",addInfo];
    [alert setAlertStyle:1];

    NSInteger button = [alert runModal];

    if(button == NSAlertDefaultReturn){
        confirmFlag = YES;

     }else{

        confirmFlag = NO;
     }

     return confirmFlag;

 }


 The [alert runModal] returns the value I can return.

Using the newer paradigm, [alert beginSheetModalForWindow:[self window]sheetWindow completionHandler: some_handler] does not allow me to update or return the value at the end of the method. I know why, but is there a way I'm not thinking of to accomplish this.

Please show me how to create a similar method to the one I've ben using for sheets.

Thanks Mie

lead_the_zeppelin

Assuming the code that calls the confirm:withMoreInfo:andTheActionButtonTitle: is called from validate.

-(void)validate
{
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:questionTitle];
// fill out NSAlert

[alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse returnCode) {
    if(returnCode == NSModalResponseStop)
    {
        confirmFlag = YES;
    }
    else
    {
        confirmFlag = NO;
    }
//Rest of your code goes in here.
}];

}

The rest of your code needs to be INSIDE the completion block.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

own completion handler in firebase function (custom class method)

From Dev

Implement custom func with completion handler

From Dev

How can I properly document a method with a completion handler in iOS swift

From Dev

How to call this completion handler?

From Java

How could I create a function with a completion handler in Swift?

From Dev

Method For Ending A Loop With Completion Handler?

From Dev

Adding a completion handler on a delegate method

From Dev

Completion Handler called in IBAction Method

From Dev

Create a list of custom objects with Inversion of Control paradigm

From Dev

How to cancel a completion handler in iOS

From Dev

How to reset a Completion Handler in Swift

From Dev

Manage completion handler of NSURLSession from a custom class

From Dev

Google SDK iOS - sign() method completion handler

From Dev

Create an NSAlert with Swift

From Dev

How to create a custom global exception handler for filters in Spring Security?

From Dev

How to pass error details to model when create a custom error handler?

From Dev

How to create a multiple choice answer sheet in word? (the fastest and easiest method)

From Dev

How to store a Closure completion handler to call later?

From Dev

How to write completion handler in Swift with animation.

From Dev

How to pass background task identifier to completion handler?

From Dev

How to add completion handler/closure for 'animated: true'

From Dev

How to properly dismiss modal viewcontroller with completion handler

From Dev

How can a completion handler return to the wrong ViewController?

From Dev

How can I use the MDCSnackbarMessage completion handler?

From Dev

Create a custom URL Protocol Handler

From Dev

Rails Faker how to create custom method

From Dev

How to create a custom circle with arc method?

From Dev

How to create a custom get method snippet in VsCode

From Dev

Rails Faker how to create custom method

Related Related

  1. 1

    own completion handler in firebase function (custom class method)

  2. 2

    Implement custom func with completion handler

  3. 3

    How can I properly document a method with a completion handler in iOS swift

  4. 4

    How to call this completion handler?

  5. 5

    How could I create a function with a completion handler in Swift?

  6. 6

    Method For Ending A Loop With Completion Handler?

  7. 7

    Adding a completion handler on a delegate method

  8. 8

    Completion Handler called in IBAction Method

  9. 9

    Create a list of custom objects with Inversion of Control paradigm

  10. 10

    How to cancel a completion handler in iOS

  11. 11

    How to reset a Completion Handler in Swift

  12. 12

    Manage completion handler of NSURLSession from a custom class

  13. 13

    Google SDK iOS - sign() method completion handler

  14. 14

    Create an NSAlert with Swift

  15. 15

    How to create a custom global exception handler for filters in Spring Security?

  16. 16

    How to pass error details to model when create a custom error handler?

  17. 17

    How to create a multiple choice answer sheet in word? (the fastest and easiest method)

  18. 18

    How to store a Closure completion handler to call later?

  19. 19

    How to write completion handler in Swift with animation.

  20. 20

    How to pass background task identifier to completion handler?

  21. 21

    How to add completion handler/closure for 'animated: true'

  22. 22

    How to properly dismiss modal viewcontroller with completion handler

  23. 23

    How can a completion handler return to the wrong ViewController?

  24. 24

    How can I use the MDCSnackbarMessage completion handler?

  25. 25

    Create a custom URL Protocol Handler

  26. 26

    Rails Faker how to create custom method

  27. 27

    How to create a custom circle with arc method?

  28. 28

    How to create a custom get method snippet in VsCode

  29. 29

    Rails Faker how to create custom method

HotTag

Archive