Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3841872
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:42:48+00:00 2026-05-19T15:42:48+00:00

I’m a complete n00b with MacRuby and Cocoa, so keep that in mind when

  • 0

I’m a complete n00b with MacRuby and Cocoa, so keep that in mind when answering – I need lots of details and explanation. 🙂

I’ve set up a simple project that has 2 windows in it, both of which are built with Interface Builder. The first window is a simple list of accounts using a table view. It has a “+” button below the table. When I click the + button, I want to show an “Add New Account” window.

I also have an AccountsController < NSWindowController and a AddNewAccountController < NSWindowController class, set up as the delegates for these windows, with the appropriate button click methods wired up, and outlets to reference the needed windows.

When I click the “+” button in the Accounts window, I have this code fire:

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

this works great the first time I click the + button. Everything shows up, I’m able to enter my data and have it bind to my model. however, when I close the add new account form, things start going bad.

if I set the add new account window to release on close, then the second time I click the + button, the window will still pop up but it’s frozen. i can’t click any buttons, enter any data, or even close the form. i assume this is because the form’s code has been released, so there is no message loop processing the form… but i’m not entirely sure about this.

if i set the add new account window to not release on close, then the second time i click the + button, the window shows up fine and it is usable – but it still has all the data that i had previously entered… it’s still bound to my previous Account class instance.

what am I doing wrong? what’s the correct way to create a new instance of the Add New Account form, create a new Account model, bind that model to the form and show the form, when I click the + button on the Accounts form?

… this is all being done on OSX 10.6.6, 64bit, with XCode 3.2.4

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:42:48+00:00Added an answer on May 19, 2026 at 3:42 pm

    The issue is that it doesn’t create the window each time. Release on close is a bit of an annoying option and generally is only used if you know the window controller is also being released when the window closes. (Note I’ve never used MacRuby so I’ll be giving code in Obj-C as I know that it is correct, hopefully you can convert it. I’ll be assuming GC is on as it should be with MacRuby).

    Now there are two ways to do this. I’m not entirely sure how your NIB/classes are set up as it could be one of two ways.

    —

    The first way to solve it is to use the outlets you use to reference the form elements to blank them out when you display the window again eg [myTextField setStringValue:@””]. If you’re using cocoa bindings then it’s a little trickier, but basically you have to make sure the bound object is blanked out. I would recommend against bindings though if you are new to Cocoa.

    —

    The second way is to make the AddNewAccountController class a subclass of NSWindowController. When you press the + button you would then create a new instance of it and display it (remember to store it in an ivar). The best way to do it would be as so:

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

    This prevents a new instance being made if the window is already visible. You then need to implement the delegate:

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

    Obviously you would need to move the window to a separate NIB called “AddNewAccountController”. In this NIB make sure to set the class of the File’s Owner to AddNewAccountController and then to connect the File’s Owner’s window outlet to the window.

    When all this is set up, you will get a fresh controller/window each time. It also has the benefit of splitting up nibs and controllers into more focused units.

    —

    One last thing. While it is fine to do something like this in a window, you may want to eventually look at doing this via a sheet, as it would then prevent the possibility of the add account window getting hidden behind other windows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.