Getters/Setters/将一个对象分配给另一个对象
我有一门叫做主席的课程。
我有一个视图控制器,其中包含一个椅子类型的对象。
在某些时候,我试图将我的 viewcontrollers 实例分配给 Chair 对象的另一个实例,如下所示:
[viewcontroller setChair: thisChair];
我的 setter 看起来像这样:
- (void) setChair:(Chair *)thisEntryChair;
{
myVCChair = thisEntryChair;
}
我收到此错误:
[setChair:]: unrecognized selector sent to instance
无论我使用 setter 函数还是直接使用 setter 函数还是使用 setter:
viewcontroller.myVCChair = thisEntryChair;
这方法,如果我以与我相信我有的其他变量相同的方式完成它,我认为存在问题,因为这是一个自定义对象而不是内置对象?
帮助!
I have a class called Chair.
I have a view controller that contains an object of type Chair.
At some point, I am trying to assign my viewcontrollers instance to another instance of a Chair object as such:
[viewcontroller setChair: thisChair];
My setter looks as such:
- (void) setChair:(Chair *)thisEntryChair;
{
myVCChair = thisEntryChair;
}
I am getting this error:
[setChair:]: unrecognized selector sent to instance
whether I use a setter function or plainly as such or use a setter:
viewcontroller.myVCChair = thisEntryChair;
This approach, if I have done it in the same manner as I have other variables which I believe I have, I assume is having issues as this is a custom object not an inbuilt one?
Help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为类名和字段名相同可能会出现问题。尝试重命名您的成员变量aChair
或其他名称,看看它是否有效。然后您可以选择一个您更喜欢的名称。根据问题编辑更新:
如果您想要自己的设置器,则不应使用@synthesize。 setter 应该被命名
然后你可以使用 viewcontroller.myVCChair = anotherChair
I think the class name and the field name being the same might be a problem. Try renaming your member variableaChair
or something to see if it works. Then you can choose a name you like better.UPDATE BASED ON QUESTION EDIT:
@synthesize shouldn't be used if you want your own setter. The setter should be named
Then you can use
viewcontroller.myVCChair = anotherChair
所以在您的示例中,代码将是:
或
内部类 ivar myVCChair 未公开。
so in your example the code would be:
or
The internal class ivar myVCChair isn't exposed.