Search code examples
rubycocoamacosmacruby

MacRuby, sheet error


I'm running with MacRuby 0.5 and I have a method:

 attr_accessor :bookmarkSheet, :mainWindow

def createBookmark(sender)
  NSApp.beginSheet(bookmarkSheet, 
   modalForWindow:mainWindow, 
   modalDelegate:self, 
   didEndSelector:nil,
   contextInfo:nil)   
 end

which is supposed to open up a sheet panel on the main window. However, whenever I run this method, I get

2009-10-10 12:27:45.270 Application[45467:a0f] nil is not a symbol

Any thoughts as to why I get this error? I can't seem to find anywhere that lists the reason I am getting this error. Thanks


Solution

  • Peter is right, didEndSelector: is expecting a selector, you should try something like:

    def bookmark_created
     puts "Bookmark created"
    end
    
    def createBookmark(sender)
      NSApp.beginSheet(bookmarkSheet, 
       modalForWindow:mainWindow, 
       modalDelegate:self, 
       didEndSelector:"bookmark_created:",
       contextInfo:nil)   
     end
    

    Notice how I added a colon after the name of the method to call. Also, it looks like a bug with MacRuby beta release, I would encourage you to report the bug on the MacRuby tracker: http://www.macruby.org/trac/newticket

    Here is the example given by Apple's documentation:

    - (void)showCustomDialog: (NSWindow *)window
    // User has asked to see the dialog. Display it.
    {
        if (!myCustomDialog)
            [NSBundle loadNibNamed: @"MyCustomDialog" owner: self];
    
        [NSApp beginSheet: myCustomDialog
                modalForWindow: window
                modalDelegate: nil
                didEndSelector: nil
                contextInfo: nil];
        [NSApp runModalForWindow: myCustomDialog];
        // Dialog is up here.
        [NSApp endSheet: myCustomDialog];
        [myCustomDialog orderOut: self];
    }
    

    As you can see, you should be able to set the end selector as nil. In the meantime, my workaround will work just fine.

    Good luck,

    • Matt