質問

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];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top