I'm trying to set up a Sudoku number puzzle solving tool, which
involves (in part) having a nine by nine grid in a window. Each cell of
this grid contains the digits 1 through 9 in a 3x3 array.
I have this window, and one cell, in a separate NIB file from the
MainMenu file. So I can use code like this to open that window and
instantiate the contents:
mainWindow = SudokuWindow.alloc.init.createWindow
(createWindow is a method I created in SudokuWindow for working on the
window, since :window isn't defined when the init code runs)
So far so good. Now, I need 80 more cells like the one already in the
NIB file, but trying to create them "by hand" seems more than a little
crazy. The nine digits are represented as an NSMatrix of NSButtonCells,
and the NSMatrix is linked to
class SuCell < OSX::NSObject
blah blah blah
end
I can't figure out how to make copies of the cell I have. One approach
would be to make SuCell create the interface elements to which it's
bonded. However, trying to recreate this NSMatrix programmatically
seems very complicated. It would be so much easier to just duplicate
the one I have already built in Interface Builder, except I can't
figure out how.
I can usually see the window by accessing self.window from within the
WindowController code, but attempting to access self.window.contentView
always returns nil, or sometimes an error complaining that self.window
itself is nil, even though if I ask Ruby to "p self.window" I do get an
NSWindow object dumped in the log.
I'd hoped to use Cocoa's "copy" function to duplicate the NSMatrix. I
could then create a new SuCell and programmatically link the elements.
Except I can't figure out how to "get" the first IB object to copy it.
How do I access the actual instantiated object(s) in order to invoke
the Cocoa "copy" method?
I hope I've asked the right question. :)
Thanks!
|