• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Prevent Asynchronous operation of beginSheetModalForWindow
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Prevent Asynchronous operation of beginSheetModalForWindow


  • Subject: Re: Prevent Asynchronous operation of beginSheetModalForWindow
  • From: "John Love" <email@hidden>
  • Date: Fri, 27 Jun 2008 10:38:28 -0400

Graham,

Yup, Nathan the double indirection of id *

1st, just the key snippet from FileController.m:

@implementation FileController

id mFileSheetDelegate;

=====

Here's the complete interface and implementation files for just one
SheetController, which has 2 buttons in its sheet window:

// SaveSheetController.h

#import <Cocoa/Cocoa.h>

@interface SaveSheetController:NSWindowController {
    IBOutlet NSTextField *iboSaveDescription;
}
- (void) showSheetOnParentWindow:(NSWindow*)parentWindow
                                 withDescription:(NSString*)theDescription
                                 delegate:(id)theTarget
                                 contextInfo:(void*)contextInfo;
- (void) sheetDidEnd:(NSWindow*)sheet
                     returnCode:(int)returnCode
                     contextInfo:(void*)contextInfo;
- (IBAction) saveIt:(id)sender;
- (IBAction) dontSaveIt:(id)sender;
- (void) closeSheet:(id)sender withCode:(int)theCode;
@end

===========

// SaveSheetController.m

#import "SaveSheetController.h"

enum {
    kJustSave,   /* 0, 1 */
    kJustNotSave
};

@implementation SaveSheetController

extern id mFileSheetDelegate;

- (void) showSheetOnParentWindow:(NSWindow*)parentWindow
                                 withDescription:(NSString*)theDescription
                                 delegate:(id)theTarget
                                 contextInfo:(void*)contextInfo {
    mFileSheetDelegate = theTarget;

    if (theDescription) {
        // do magic
    }

    [NSApp beginSheet:[self window]
                      modalForWindow:parentWindow
                      modalDelegate:theTarget
                      didEndSelector:@selector
(sheetDidEnd:returnCode:contextInfo:)
                      contextInfo:contextInfo];
}

// 2 buttons of saveSheet
- (IBAction) saveIt:(id)sender {
    [self closeSheet:sender withCode:kJustSave];
}

- (IBAction) dontSaveIt:(id)sender {
    [self closeSheet:sender withCode:kJustNotSave];
}

- (void) closeSheet:(id)sender withCode:(int)theCode {
    NSWindow* theSheet;
    theSheet = [sender window];

    [NSApp endSheet:theSheet returnCode:theCode];   // calls didEndSelector
}

- (void) sheetDidEnd:(NSWindow*)sheet
                     returnCode:(int)returnCode
                     contextInfo:(void*)contextInfo {
    [mFileSheetDelegate doSheetSelection:returnCode
contextInfo:contextInfo];

    [sheet orderOut:self];
}

@end

========

Finally, a snippet or two from [doSheetSelection:contextInfo]:

- (void) doSheetSelection:(int)returnCode
                          contextInfo:(void*)contextInfo {

    /*
        If we had different sheets returning the same code,
        then we would select between the different sheet IDs.
        But, for our case, all returned IDs are unique.

    if ([(NSString*)contextInfo isEqualToString:sCalculateSheetID]) {
    }
    if ([(NSString*)contextInfo isEqualToString:sSaveSheetID]) {
    }
    if ([(NSString*)contextInfo isEqualToString:sErrorSheetID]) {
    }
    */

    switch (returnCode) {
        case kJustSave:
            [self saveSpreadsheet];

            gShouldCloseDoc = TRUE;
            break;

        case kJustNotSave:
            [self setStatus:sFileNotSavedMsg];

            gShouldCloseDoc = TRUE;
            break;
    }

========

Okay ... all the snippets are done ... now, the questions:

(1) warning: no doSheetSelection:contextInfo method found which, I think, is
due to the fact that the external class of mFileSheetDelegate =
FileController, yet when referenced in SaveSheetController, it's = id, a
general pointer.  But, I thought all anonymous pointers were resolved at
runtime ... am I just going to force myself to ignore this Build Warning,
knowing that it will all go away at runtime???

(2)I still get "unrecognized selector" .. but,
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
is within the sheet.m .. good grief!

John
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Prevent Asynchronous operation of beginSheetModalForWindow
      • From: Graham Cox <email@hidden>
References: 
 >Prevent Asynchronous operation of beginSheetModalForWindow (From: "John Love" <email@hidden>)
 >Re: Prevent Asynchronous operation of beginSheetModalForWindow (From: "John Love" <email@hidden>)
 >Re: Prevent Asynchronous operation of beginSheetModalForWindow (From: Graham Cox <email@hidden>)
 >Re: Prevent Asynchronous operation of beginSheetModalForWindow (From: "John Love" <email@hidden>)
 >Re: Prevent Asynchronous operation of beginSheetModalForWindow (From: "John Love" <email@hidden>)
 >Re: Prevent Asynchronous operation of beginSheetModalForWindow (From: "John Love" <email@hidden>)
 >Re: Prevent Asynchronous operation of beginSheetModalForWindow (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: NSString uppercaseString
  • Next by Date: Catching the delegate message in a subclass
  • Previous by thread: Re: Prevent Asynchronous operation of beginSheetModalForWindow
  • Next by thread: Re: Prevent Asynchronous operation of beginSheetModalForWindow
  • Index(es):
    • Date
    • Thread