就像标题所说,我想指定 NSArrayController
的超级,类似于 self = [super[NSArrayController] function]
,但没有运气搜索为了这。有什么想法吗?提前致谢。
编辑删除抽象示例,因为它们使人们对我的问题的性质感到困惑。
这样做的目的是以编程方式执行从 NSArrayController 到 NSButton 的“add”简单绑定在 IB 中执行的操作。我的应用程序中有多个 arrayController,因此我希望能够指定要通过代码获取哪个 arrayController。
我正在寻找 NSArrayController 的 super 的原因是因为我的印象是应该解决模型而不是控制器(NSArrayController),并且我的模型是一个核心数据模型,我相信我可以通过使用 super 来访问它我通过名称指定的 NSArrayController 的。也许有一种更直接的方法来添加到数据模型。
Like the titles says, I want to specify the super of an NSArrayController
, something along the lines of self = [super[NSArrayController] function]
, but have had no luck searching for this. Any ideas? Thanks in advance.
Edited to remove abstract examples as they're confusing people as to the nature of my question.
The purpose of this is to programmatically do what a simple binding of 'add' from an NSArrayController to an NSButton would do in IB. There are several arrayControllers in my application so I want to be able to specify which one I want to obtain the super of by code.
The reason I am looking for the super of an NSArrayController is because I am under the impression that one should address the model rather than the controller (NSArrayController) and my model is a Core Data model that I believe I could get to by using the super of an NSArrayController I specify by name. Perhaps there is a more direct way of adding to the data model.
发布评论
评论(1)
你问了一个错误的问题。
首先,让我们区分类和类的实例。请注意,同一个类可以存在并且确实经常存在多个实例。
类
C
可以是另一个类A
的子类。那么A
就是C
的超类。假设您有一个C
类的实例c
。然后,在C
类的方法的实现中,self
代表c
本身的实例,super
代表code> 代表c
的实例作为其超类A
的实例。从某种意义上说,C
类的实例也是A
类的实例。对象可以具有除超类或子类之外的其他关系。例如,类
C
可以在其接口中包含实例变量B* b;
在这种情况下,类c
的实例 < code>C 有指向类B
的实例b
的指针。在这种情况下,c
不是类B
的实例。NSArrayController 和托管对象上下文之间的关系是后者之一。 NSArrayController 的实例包含指向 NSManagedObjectContext (moc) 实例的指针。
所以你想要做的不是获取你的
NSArrayController
的super
。相反,您想要获取与 NSArrayController 关联的 moc。现在,你如何得到它?要找到它,您可以在 XCode 中或在 Apple Developer Connection 的 Web 上打开参考,参见此处。现在就这样做。通过这些方法。你找不到一个给你 moc 的人。然后,您转到该页面的顶部,并遵循
NSArrayController
的超类。请参阅NSObjectController
的此引用。现在,浏览一下方法列表。您会找到-[NSObjectController ManagedObjectContext]
,它就完成了这项工作!总之:如果您想要与
NSArrayController
关联的 moc,您只需要执行以下操作,其中
arrayController
是您想要的NSArrayController
的实例处理。例如,如果笔尖中有多个 NSArrayController 实例,则应用程序委托中应该有多个 IBOutlet,例如 arrayController1,< code>arrayController2 等(这些都是非常糟糕的变量名)。然后你选择你想要处理的人。You're asking a wrong question.
First, let's distinguish a class and an instance of the class. Note that there can be, and indeed often are, multiple instances of the same class.
A class
C
can be a subclass of another classA
. ThenA
is the superclass ofC
. Suppose you have an instancec
of the classC
. Then, in the implementation of the methods of the classC
,self
stands for the instance ofc
itself, andsuper
stands for the instance ofc
as an instance of its superclassA
. In a sense, an instance of the classC
is also an instance of the classA
.Objects can have other relationships than being super or subclasses. For example, a class
C
can have in its interface an instance variableB* b;
In this case, an instancec
of the classC
has a pointer to an instanceb
of the classB
. In this case,c
is not an instance of the classB
.The relationship between
NSArrayController
and the managed object context is one of the latter. An instance ofNSArrayController
contains a pointer to an instance ofNSManagedObjectContext
(moc).So what you want to do is not to get the
super
of yourNSArrayController
. Instead, you want to get the moc associated to theNSArrayController
. Now, how do you get it? To find it out, you open the reference in XCode or on the web at the Apple Developer Connection, see here. Do that right now. Go through the methods. You don't find one giving you the moc.Then, you go to the top of that page, and follow the superclass of
NSArrayController
. See this reference ofNSObjectController
. Now, go through the list of the methods. You find-[NSObjectController managedObjectContext]
, which does the job!In conclusion: if you want the moc associated to the
NSArrayController
, you just need to dowhere
arrayController
is the instance of theNSArrayController
you want to deal with. e.g. If you have multiple instances ofNSArrayController
s in the nib, you should have multipleIBOutlet
s in the app delegate, say,arrayController1
,arrayController2
, etc. (which are very bad variable names). Then you choose the one you want to deal with.