开发者

Access IB Object from Custom Class

开发者 https://www.devze.com 2023-04-06 09:02 出处:网络
This is a silly beginner question but... If I have a custom subclass of NSTextView \"SSTe开发者_如何转开发xtView\" that spawns from Interface Builder, how do I access the instance of my custom class t

This is a silly beginner question but... If I have a custom subclass of NSTextView "SSTe开发者_如何转开发xtView" that spawns from Interface Builder, how do I access the instance of my custom class that is actually in the interface from inside SSTextView.m? The overall goal, I guess, is to be able to call an instance method in SSTextView.m from another method in the file. I know that [self aMethod] only works for class methods.

Now, I know I can do this from another class's implementation by using IBOutlet SSTextView *myTextView; and making the connections in Interface Builder, but it seems like an odd organizational paradigm that I wouldn't be able to put the methods that deal with my user interface text view in its own implementation.

Thanks in advance.


Did you actually tried [self aMethod]?

If you are in an instance method of SSTextView, you should be able to call an other instance method of SSTextView using [self aMethod]. As self is a pointer to the current class instance.


You've got this part backwards:

I know that [self aMethod] only works for class methods.

[self aMethod] is how you invoke an instance method on the current object.

[MyClass aMethod] is how you invoke a class method.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号