Pregunta

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];
}
¿Fue útil?

Solución

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];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top