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 6995865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:05:04+00:00 2026-05-27T20:05:04+00:00

I have a Cocoa application built using Garbage Collection with a main window. This

  • 0

I have a Cocoa application built using Garbage Collection with a main window. This window provides a button which triggers an action on the window’s controller when it is clicked as follows:


- (IBAction) buttonClick:(id)sender {
    utilityWindowController = [[UtilityWindowController alloc] initWithWindowNibName:@"Utility"];
    [utilityWindowController showWindow:sender];
}

This works fine, except that every time the button is clicked, a new window is opened, even if the one I got last click is still displayed. Ok – that’s what I’ve asked it to do, but I want only one instance of this window at a time. So the behaviour I want is:

  1. if the window is not displayed, create a new one and show it.
  2. if the window is being shown, either do nothing, or maybe focus the existing window (bring to front etc).

To try to get this behaviour, I tried this:


- (IBAction) buttonClick:(id)sender {
    if (!utilityWindowController) {
        utilityWindowController = [[UtilityWindowController alloc] initWithWindowNibName:@"Utility"];
    }
    [utilityWindowController showWindow:sender];
}

So that works better, because now my main window remembers the controller I created the first time I clicked the button and just shows the window if it already has one. However, it is basically reusing the same window, which causes another problem.

The utility window has a graphical display and starts a timer when it is first created. The utility window controller has a windowWillClose: method that disables the timer when the window is closed, since it’s not useful to continue have the timer fire when the user can’t see the display. However, when the user clicks the button in the main window to display the utility window for a second time, the window shows just fine, but the timer is not started again.

I cannot seem to find something like a windowWillShow: method that I could use to restart the timer.

The other way would be if the code above would be able to detect that the utility window was closed and recreate a new one so the awakeFromNib method would get called to start the timer. However, I don’t know how I can do that.

A third method would of course be to proceed with the second version of the code above, but call a separate method that I will provide in the utility window controller that will start the timer if not already running.

What would be the best method of handling this type of thing? It seems like a fairly standard window management thing, but I haven’t quite worked out the correct way of doing this in Cocoa.

  • 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-27T20:05:04+00:00Added an answer on May 27, 2026 at 8:05 pm

    There isn’t a delegate method or notification when a window is ordered in.

    I would give the window controller another method that shows the window (if it isn’t already up) and starts the timer (if it isn’t already running), and have buttonClick: simply send that message to the window controller.

    The other way would be to use the original code, disable the button after creating the window controller, and re-enable the button (and destroy the window controller) when the window is closed. The disadvantage of this is that it leaves the user with no easy way to get back to the second window from the first (e.g., if they have a lot of windows on screen). If you leave the button enabled, you can have it order the window front again even if it’s already up. That’s why I’d go with my suggestion above.

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

Sidebar

Related Questions

I have come across this Cocoa application (source code) that shows a main Window.
I have a cocoa application which is a fullscreen webbrowser using WebView. Initially the
I have an webView in a Cocoa application which I edit the contents programatically.
I have two projects, a Cocoa iPhone application and a static library which it
I have a cocoa application which has certain subroutines / methods. So if I
I have a relatively simple goal: I want to create a Cocoa application which
I have a view-based iOS cocoa touch application built and is running on iPhone.
I have an XCode project built as a Cocoa single document application (it's not
I'm making a non-garbage-collected MacFUSE Cocoa application, inside of which I want to use
I have a project with one main Cocoa application, a bunch of plugins, and

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.