gpt4 book ai didi

cocoa - 关于 NSWindowController 和 NSPersistentDocument 核心数据教程的问题

转载 作者:行者123 更新时间:2023-12-03 18:04:21 24 4
gpt4 key购买 nike

NSPersistentDocument Core Data Tutorial 的实现概述部分它说:

  1. One issue with creating the new top-level object in the nib file is that when you use bindings an object retains other objects to which it is bound. This means that bindings must be broken to ensure there are no retain cycles when a document is closed. Moreover, since the nib file the new controller owns contains top level objects and the controller’s class does not inherit from NSWindowController, you need to release the top level objects when the window is closed.

为什么不直接让 Controller 继承自 NSWindowController 呢?这有什么理由行不通吗?或者这只是风格问题?

最佳答案

正如下面所评论的,我确实让它与 NSWindowController 子类一起使用,而且它似乎确实节省了相当多的代码。

这是我的子类 header :

#import <Cocoa/Cocoa.h>

@interface NewAccountSheetController : NSWindowController {
@private
BOOL isValidForInsert;
NSManagedObjectContext * managedObjectContext;
NSObjectController * objectController;
NSObjectController * targetController;
}

@property (setter=setValidForInsert:) BOOL isValidForInsert;
@property (nonatomic, retain) IBOutlet NSManagedObjectContext * managedObjectContext;
@property (nonatomic, retain) IBOutlet NSObjectController * objectController;
@property (nonatomic, retain) IBOutlet NSObjectController * targetController;

- (void)beginSheetForWindow:(NSWindow *)window;

- (IBAction)endSheet:(id)sender;

@end

这是 Pastebin 中的实现.

我不知道如何描述所需的绑定(bind)等,但如果您熟悉上面的教程,它们应该很容易推断......我认为。 :-)

关于cocoa - 关于 NSWindowController 和 NSPersistentDocument 核心数据教程的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3487804/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com