MacRuby + Interface Builder: how to display, then close, and then display the window again

I'm full n00b with MacRuby and Cocoa, so keep that in mind when replying - I need a lot of details and explanations. :)

I created a simple project in which there are two windows, both of which are built using Interface Builder. The first window is a simple list of accounts using a table view. It has a + button under the table. When I click the + button, I want to show the "Add New Account" window.

I also have a class AccountsController < NSWindowControllerand AddNewAccountController < NSWindowController, configured as delegates for these windows, using the appropriate button click and exit methods to link to the required windows.

When I click the "+" button in the "Accounts" window, this code lights up for me:

    @add_account.center
    @add_account.display
    @add_account.makeKeyAndOrderFront(nil)
    @add_account.orderFrontRegardless

this works great the first time you press the + button. Everything appears, I can enter my data and bind it to my model. however, when I close the new account form, everything starts badly.

if I set a new account window to close when closing, then the second time I click the + button, the window will still pop up, but it will be frozen. I can’t click on any buttons, enter any data or even close the form. I suppose this is because the form code was released, so there is no message processing form ... but I'm not quite sure about that.

, , , +, , , , ... - Account.

? " ", , , "+" ""?

... OSX 10.6.6, 64bit, XCode 3.2.4

+3
1

, . Release on close - , , , . (. MacRuby, Obj-C, , , , . , GC , MacRuby).

. , NIB/, .

-

- , , , , [myTextField setStringValue: @""]. cocoa, , , . , Cocoa.

-

- AddNewAccountController NSWindowController. +, ( ivar). :

if (!addAccountController) {
    addAccountController = [[AddNewAccountController alloc] initWithWindowNibName:@"AddNewAccountController"];
    [[addAccountController window] setDelegate:self];
}
[addAccountController showWindow:self];

, . :

- (void)windowWillClose:(NSNotification *)notification {
    //If you don't create the account in the AddNewAccountController then do it here
    addAccountController = nil;
}

, NIB, "AddNewAccountController". NIB , AddNewAccountController, File Owner.

, / . .

-

. - , , , , .

+1

Source: https://habr.com/ru/post/1788808/


All Articles