• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSDocument updateChangeCount doesn't
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDocument updateChangeCount doesn't


  • Subject: Re: NSDocument updateChangeCount doesn't
  • From: "Louis C. Sacha" <email@hidden>
  • Date: Fri, 22 Oct 2004 05:24:45 -0700

Hello...

The problem you are seeing is probably related to these lines of code


in MyDocument windowControllerDidLoadNib I tell my app controller who MyDocument is
myController = [[[MyAppController alloc] init] retain];
[myController setMyDoc:self];


In the first line, you create a new instance of MyAppController. The newly created instance is probably different from the one where you are expecting the other method (updateMessageLog) to be used, and in that other instance of MyAppController the setMyDoc: method is never called so myDoc is nil.

The most likely reason why your NSLog statement always indicates that isDocumentEdited is returning FALSE is that you are sending the message to a nil object (myDoc), and nil is returned when a message is sent to a nil object.

FALSE == 0 == nil == [nil someMessage]


In general, there is only one shared instance of your application level controller object, instantiated and freeze-dried in the MainMenu.nib file. This one instance is usually connected to the delegate outlet of that nib's owner which happens to be the application's shared instance of NSApplication.

Assuming you have things hooked up in MainMenu.nib as described, you can get access to that shared instance by doing

myController = (MyAppController *)[NSApp delegate];

In most cases you wouldn't want to have an object retain the controller that "owns" it, in order to avoid retain cycles that prevent both objects from being deallocated properly.


There is also another issue that you might want to consider, related to the architecture of your application. It's hard to say for sure without knowing more detailed info, but it sounds like the code you are talking about in MyAppController should actually be in the NSDocument subclass.

In other words, what happens when the user creates a second document?

It sounds like your current code uses an instance variable in the app controller to access the current document, but if a second document were to be created, there would no longer be any way to work with the first one.

If each document should have it's own timer and associated start/stop controls, then you probably want that code in the NSDocument subclass or in a controller owned by the document , so that there is one instance per document.

If there should be one timer and set of start/stop controls for the whole app, then the app controller would manage the timer and then send an updateMessageLog message to all of the open documents. In a document based app, you can get an array of all the open documents from the shared instance of NSDocumentController.


Anyway, hope that helps,

Louis

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
References: 
 >NSDocument updateChangeCount doesn't (From: Fred Glover <email@hidden>)

  • Prev by Date: Re: Currency Converter Tutorial Problems
  • Next by Date: Re: Random crash in -[NSView displayIfNeeded]
  • Previous by thread: NSDocument updateChangeCount doesn't
  • Next by thread: NSTableView Cell Selection for Contextual Menu
  • Index(es):
    • Date
    • Thread