简体   繁体   中英

NSDocument has ivar to NSArrayController

Is this ok, to load NSWindowController from NSDocument, and keep reference to NSArrayController? I need this instance of array controller to save data.

- (void)makeWindowControllers
{
ImageWindowController *controller = [[[ImageWindowController alloc] init] autorelease];
[self addWindowController:controller];
myArrayController = controller.bindingsController;
}

//save

- (NSData*)dataOfType:(NSString *)typeName error:(NSError **)outError
{
return [NSKeyedArchiver archivedDataWithRootObject:myArrayController.arrangedObjects];
}

Yes it is OK. Just make sure that myArrayController never gets released before your document subclass is released. (if it is made in IB then it will be fine) but if you instantiated the array controller in code and set it as a property of the ImageWindowController, make sure you call retain when assigning the variable like so:

myArrayController = [controller.bindingsController retain];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM