Quick Q about using sheets

Discussion in 'Mac Programming' started by stadidas, Nov 21, 2006.

  1. stadidas macrumors regular

    Joined:
    Feb 27, 2006
    Location:
    Kent, United Kingdom
    #1
    I've looked at this code for launching a custom sheet from Apple:
    Code:
    if (!myCustomSheet) 
            [NSBundle loadNibNamed: @"MyCustomSheet" owner: self];
    
        [NSApp beginSheet: myCustomSheet 
                modalForWindow: window 
                modalDelegate: self 
                didEndSelector: @selector(didEndSheet:returnCode:contextInfo:) 
                contextInfo: nil];
    
    I'm trying to use this code in MyDocument.m, but I don't know what to pass for the modalForWindow parameter. Everything I try gets an error. Does anyone know what to pass it to get a sheet to load in the MyDocument window?
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    If you're calling it from your NSDocument subclass (MyDocument by default), you can use the windowForSheet method.
     
  3. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #3
    First of all, what is the error you're getting? And how do you know that it's the "modalForWindow" parameter that's causing the error? Also, what class are you calling it from (and what superclasses)? And from what method? For example, is "window" a valid object? It won't be if awakeFromNib:/windowDidLoadNib: has not been called, or if that outlet hasn't been connected to a window in IB.
     
  4. caveman_uk Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #4
    It depends what your controller object is a subclass of. Is 'window' defined? Maybe [self window] would work better if it is? If it isn't, define an IBOutlet NSWindow* in your code and connect it in IB to the parent window in IB.
     
  5. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #5
    Looking at an example in my own code, I was using [self window]. But yeah...it really depends.
     
  6. stadidas thread starter macrumors regular

    Joined:
    Feb 27, 2006
    Location:
    Kent, United Kingdom
    #6
    I used kainjow's solution which worked very nicely.
     

Share This Page