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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:46:40+00:00 2026-05-27T04:46:40+00:00

I am writing a Cocoa/Objective-C app in XCode4, and I need to know when

  • 0

I am writing a Cocoa/Objective-C app in XCode4, and I need to know when my preferences panel is opened. I need some callback like windowDidBecomeKey; I attempted to follow the solution provided in this question, but neither windowDidBecomeKey or windowDidExpose appear as delegate methods(but others, like windowDidLoad, windowWillLoad, etc do).

To clarify exactly what I mean by “don’t appear as delegate methods”, I mean they don’t show up in the auto complete when I begin typing the method name. I did try defining them anyway, but they were never called.

Do NSPanel objects lack these methods, or is there something more I have to do?

Currently, I have an interface PrefWindowController:

PrefWindowController.h:

#import <Cocoa/Cocoa.h>

@interface PrefWindowController : NSWindowController
    //Delegate methods like windowDidBecomeKey appear to not be available here
@end

PrefWindowController.m:

@implementation PrefWindowController

- (id)initWithWindow:(NSWindow *)window
{
    self = [super initWithWindow:window];
    if (self) {
        NSAlert *alert = [[[NSAlert alloc] init] autorelease];
        [alert setMessageText:@".."];
        [alert runModal];
    }

    return self;
}

- (void)windowDidLoad
{
    NSAlert *alert = [[[NSAlert alloc] init] autorelease];
    [alert setMessageText:@"Loaded"];
    [alert runModal];
}

@end

When the window loads from the .xib as the application starts, windowDidLoad fires and the notification defined above is shown. I did this just to test that methods were actually getting called.

Any advice about how to get a callback for when the panel becomes key or takes focus would be very helpful.

Update:

I added a windowDidBecomeKey method to the window controller, like so:

PrefWindowController.h:

- (void)windowDidBecomeKey:(NSNotification *)notification;

PrefWindowController.m:

- (void)windowDidBecomeKey:(NSNotification *)notification
{
    NSLog(@"Test");
}

The test message gets logged the first time I open the window, but on the return line in my main.m file I get the error:

Thread 1: Program Received Signal: “EXC_BAD_ACCESS”

  • 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-27T04:46:41+00:00Added an answer on May 27, 2026 at 4:46 am

    The NSWindowDelegate protocol has the following methods

    - (void)windowDidBecomeKey:(NSNotification *)notification
    - (void)windowDidResignKey:(NSNotification *)notification
    

    so you can set your NSWindowController as the NSWindow delegate to get this callback. You can also register for these notifications:

    NSWindowDidResignKeyNotification
    NSWindowDidBecomeKeyNotification
    

    NSPanel is an NSWindow subclass so all this behaviour applies in your case.

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

Sidebar

Related Questions

I'm writing a Cocoa app in Objective C that's communicating with a webservice and
I'm writing a Cocoa app that will need access to multiple file transfer protocols,
I'm writing code in AppleScript to glue an Obj-C Cocoa app to some other
I'm writing a Cocoa application in Objective-C, and I would like to be able
i need a simple logging solution while writing Cocoa/OpenGL application in C++. I'd like:
When writing an application for MacOSX, using Cocoa/Objective-C, I'd like to be able to
I'm writing a Cocoa app and basically I have a window and I need
I'm writing a Cocoa application where I have an auto generated app delegate:(MyAppDelegate.h/MyAppDelegate.m) So
I have a Cocoa app I'm writing that has an ImageView with a TextView
Let's say, for illustration, I was writing an iTunes clone app in Cocoa, that

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.