NSObject 可能无法响应方法
对此有几个问题,但没有一个对我有帮助。我无法理解“调用一个类方法”是如何进行的。
我在 Interface Builder 中放置了一个 NSObject。 我对它进行了子类化。 我将对象连接到表视图。 我实现了填充表视图的方法。 我使用在对象内部声明的数组来填充表视图。 我尝试添加一些随机对象。所有方法都运行良好。 我实现了一种“addSome”方法,该方法采用一个参数并向数组添加一个对象,然后重新加载表视图。没有警告。
我在 appdelegate 类中添加了一个出口。该插座引用了关心表视图的 NSObject。但是,当调用...
[outlet addSome...]
我有一个警告:
“NSObject”可能不会响应“-addSome”[...]
该方法永远不会被调用。我无法添加任何东西。关于消息传递、函数调用和类似的事情,有什么我没有理解的概念吗?
感谢您的帮助。
There are a few questions about this, but none of them helped me. I can't understand how things go about "calling one class method".
I put a NSObject in Interface Builder.
I subclassed it.
I connected the object to a table view.
I implemented the methods to populate the table view.
I used an array, declared inside the object, to populate the table view.
I tried to add some random objects. All the methods are working perfectly.
I implemented an "addSome" method which takes one argument and adds an object to the array, then it reloads the table view. No warnings.
I add an outlet in the appdelegate class. That outlet refers to the NSObject which cares about the table view. But, when calling...
[outlet addSome...]
I have a warning:
'NSObject' may not respond to '-addSome' [...]
That method is never called. I can't add anything. Is there any concept I am not catching about messaging, function calls and things like that?
Thank you for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将实例变量的类型声明为 NSObject 子类的类型。
运行时看到它是一个 NSObject,它没有定义方法,但是如果您将类型更改为定义了方法的子类的类型,它应该可以正常工作。
You need to declare the type of your instance var to be the type of your NSObject subclass.
The runtime sees it's an NSObject, which doesn't have the method defined on it, but if you change the type to the type of your subclass which has the method defined on it, it should work fine.