NSDocument has ivar to NSArrayController
-
01-03-2021 - |
Pergunta
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];
}
Solução
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 em: CC-BY-SA com atribuição
Não afiliado a StackOverflow