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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:31:04+00:00 2026-05-25T10:31:04+00:00

Currently I’m learning Obj-C for Mac developing, with Cocoa. I made a simple file

  • 0

Currently I’m learning Obj-C for Mac developing, with Cocoa. I made a simple file browser with an inspector, to see a file’s icon an some info. So far, so good. Now I made it document based, so I could have more than one open windows.

To tell the inspector which file it should inspect, I use the NSWindowDidBecomeMainNotification. Works fine for switching between windows, but it gives an EXC_BAD_ACCESS when I close all windows and then open a new one.

This is the method that handles the notification:

- (void)windowChanged: (NSNotification *)notification
{
    NSWindow *window = [notification object];
    BrowserWindow *doc = [[window windowController] document];

    if (currentDocument != doc) {

        [currentDocument.arrayController removeObserver: self
                                             forKeyPath: @"selectionIndex"];

        [icon setImage:nil];
        [size setStringValue:@"-"];
        [owner setStringValue:@"-"];
        [filename setStringValue:@"(none selected)"];

        [doc.arrayController addObserver: self
                              forKeyPath: @"selectionIndex"
                                 options: NSKeyValueObservingOptionNew 
                                 context: NULL];
        currentDocument = doc;
    }
}

The error occurs where it calls removeObserver:forkeyPath: on the currentDocument.arrayController. It kinda makes sense, it tries to remove the observer for something that doesn’t exist anymore, ’cause the window is closed. But how to fix it? I just can’t think of anything else..

Could someone point me in the right directions?

I appreciate the help! 🙂

—

It’s getting weirder.. Just checked the example that was downloadable from the website of the book I’ve got, and they’re using the same approach, but it works all fine. Can’t find any differences, it’s driving me crazy.

—

Solved! More details later.

  • 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-25T10:31:05+00:00Added an answer on May 25, 2026 at 10:31 am

    To tell the inspector which file it should inspect, I use the NSWindowDidBecomeMainNotification. Works fine for switching between windows, but it gives an EXC_BAD_ACCESS when I close all windows and then open a new one.

    This is part of the problem right there. When the last window closes, no window will become main. So, you also need to handle the case where a window resigns main, as happens when it closes (and when another window becomes main).

    Your inspector probably should both retain the document and switch documents after a delay, using a timer (whose fire date you postpone every time another did become/resign main notification comes in) or delayed perform (which you cancel and re-perform every time). When the timer/perform fires, find out what document, if any, is the active document, and update the inspector accordingly.

    Also note that you can have no active document (no document window is the main window) even when there are documents open. The About panel and your Preferences panel are two good ways to achieve (and test) this.

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

Sidebar

Related Questions

Currently I'm doing some unit tests which are executed from bash. Unit tests are
Currently, I am developing a product that does fairly intensive calculations using MS SQL
Currently I'm trying to parse some html and return an array with the values
Currently createPopup() is only supported in IE (See http://help.dottoro.com/ljsxcrhv.php ). Is there a universal
Currently we use log4net of version 1.2.10.0 and we should start using some 3rd
I want use html5's new tag to play a wav file (currently only supported
Currently in a simple form i have the following declared table in code: declare
Currently on some operations I have to delete the old data and insert new
Currently, I pass the StackFrame to grab the current file/line number: Log.Message(new StackFrame(0, true),
Currently I am trying to render a .obj model that I loaded into vectors.

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.