• 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
Problem with Duplicate Notifications, possibly due to bad dealloc and init of document controller & window controller
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with Duplicate Notifications, possibly due to bad dealloc and init of document controller & window controller


  • Subject: Problem with Duplicate Notifications, possibly due to bad dealloc and init of document controller & window controller
  • From: Eric <email@hidden>
  • Date: Sun, 13 May 2007 18:18:47 +1000

Hi Folks,

I am really stumped on this one.

I have been writing an document based Cocoa application to track diet (food description, protien content, carb content, fat content and calorie content) for people exercising to either gain or lose weight. This is my first foray into Coca so uses a lot of the base stuff created when a Coca document based application is created.

I have a MyDocument class which has all the main diet window in it. Essentially an NSTableView connected to an NSArrayController bound to an NSMutableArray. That bit works pretty well if you are manually entering food each time. I have added a SpeedList document which is the same as the above but saves to a different document and connected to a different NSArrayController and NSMutableArray.

To communicate between the different objects when a user clicks on a food in the SpeedWindowController a notification is sent to the SpeedList document that gets all the relevant information out of the NSMutableArray, packs it into another notification and sends it to MyDocument which unpacks it and puts it in the NSMutableArray of food that has been eaten. Probably not the best way to do it and if I went right back to the drawing board I would probably just have a second window rather than a whole new document and window controller.

In the nib file that I use for the quick entry screen I have made my SpeedWindowController the first responder.

I have added an item to the windows menu which is connected to an AppController class. The app controller class has the following code to bring on the Speed List window.

-(IBAction)showSpeedList:(id)sender
{
	NSLog(@"running showSpeedListWindow");
	speedList = [[SpeedList alloc] init] ;
}

SpeedList is the document class so in the init of the SpeedList class I have the following code:

-(id)init
{
/* Need to come back and look at this init method... it's shocking */
NSLog(@"initing SpeedList");
self = [super init];

/* Let's now register speedlist as an observer for the notifcation ERFFoodToAdd coming from SpeedWindowController */
NSNotificationCenter *nc;
nc=[NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(forwardFood:) name:@"ERFFoodToAdd" object:nil];
NSLog(@"Registed with notification centre");

/*define windows controller and run */
SpeedWindowController *speedWindowController=nil;
speedWindowController=[[[SpeedWindowController alloc] initWithWindowNibName:@"SpeedList"] autorelease];
[self addWindowController:speedWindowController];
NSLog(@"window controllers %@",[self windowControllers]);
[speedWindowController showWindow:self];
NSLog(@"%@",[speedWindowController document]);


//The following automatically loads the speedlist file
NSUserDefaults *defaults;
defaults = [NSUserDefaults standardUserDefaults];
BOOL readSuccess = [self readFromFile:[defaults objectForKey:@"PathToSpeedListFile"] ofType:@"SpeedList File"];
if(readSuccess)
{
[NSKeyedUnarchiver unarchiveObjectWithData:quickFood];
}

}


Now, my problem is that when I first open the SpeedList from the mainmenu nib I can insert food into MyDocument just fine. The second time I run the speedlist from the mainmenu nib file MyDocument receives two notifications, the third time three notifications etc. By playing around with various statements to the console I think it may be due to the way I have initialized the document / window controller combination but would really appreciate it if someone could expand on how this should be done and how to fix this? I can't find too many good resources on the web for multi document applications. There's quite a few on single document, multi window applications.

Thanks in advance for any assistance.

Cheers,
EF.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Safe alternative to NSPrintInfo ?
  • Next by Date: Re: Artifacts in toolbar
  • Previous by thread: Safe alternative to NSPrintInfo ?
  • Next by thread: Determining required physical space for a HTML segment
  • Index(es):
    • Date
    • Thread