On Aug 20, 2004, at 3:00 PM, Sherm Pendley wrote:
On Aug 20, 2004, at 5:30 PM, Alan Olsen wrote:
On Aug 20, 2004, at 1:34 PM, Sherm Pendley wrote:
my $row = NSApplication->sharedApplication()->runModalForWindow($self- >myPanel());
How do you set the datasource for tableview. I usually call it right after displaying the window. I am not certain what procedure to put it in since there is not a constructor for the window that I am aware of.
Are you asking when to call setDatasource:? Whenever you want.
You could do it in the controller class' constructor - the "MyPanel" outlet is connected when you load the .nib, even if the window is offscreen. The table view won't actually call the data source methods until it actually needs to display data; i.e. when the window its in appears onscreen.
You could delay it until just before calling runModalForWindow().
You could make the controller the delegate of MyPanel, and implement the NSWindow delegate method windowDidBecomeKey:. (Careful if you do this though; the controller is also the delegate of the main window, so in the delegate method, you'll have to check *which* window became key.)
You could create a separate object, and assign it to be both the datasource and the delegate of MyPanel in the controller's constructor. It could initially be empty, and fill and/or empty itself in response to the windowDidBecomeKey: and windowDidResignKey: delegate methods.
You could do it in Interface Builder. Double-click the scroll view to select the table view inside it, then control-drag a connection from it to "File's Owner" and select the "datasource" outlet.
Believe it or not, I actually got it working!
I had to move back to my previous code and then extrapolate what was going on.
At some point I will post the code that i came up with. (After I clean it up so it does not look so Gordian knot-like.)
The call to runModalForWindow: won't return until the modal session is stopped with stopModal, stopModalWithCode:, or abortModal. Let's assume you want it to return the selected row in TableView. In the action handler for the OK button, you'd have something like this:
sub okClicked : Selector(okClicked:) ArgTypes(@) ReturnType(v) { my ($self, $sender) = @_; my $rowSel = $self->tableView()->selectedRow(); NSApplication->sharedApplication()->stopModalWithCode($rowSel); }
This does not want to kill the window. I am looking for the description in the api docs. It looks like it is missing a reference to what window needs to be destroyed.
It closes whatever window is running modally. Since, by definition, only one window can be running modally at any given time, there's no need to refer to a specific window.
Actually it appears to break the modal loop, not close the window. I just close the window before that and everything is happy.