开发者

Is it possible to set property object variable in another class in iphone?

开发者 https://www.devze.com 2023-01-13 20:32 出处:网络
I have a property in my UIView class, something like that: myView.h @ interface MyView: UIView { id refView;

I have a property in my UIView class, something like that:

myView.h

@ interface MyView: UIView {

id refView;

}

@property (nonatomic, retain) id refView;

MyView.m

@synthesis refView;

Then in another class can I set the refView proper开发者_如何学Goty of MyView something like that:

MyViewController.h

@interface MyViewController: UIViewController {

UIView *myView;

}

@property (nonatomic, retain) IBOutlet UIView *myView;

then in MyViewController.m:

[self.myView setRefView:someValue];

When I do that I get this warning: UIView may not response to '-setRefView:' ...

So, is the above way is right or what's the right way to do it. Any help and explanation would be greatly appreciate it. Thanks.


You added the refView property to MyView class, not UIView, that's why the compiler complains. If you initialize myView with a MyView instance, this will work, even if there's a warning.

To prevent the compiler from complaining, change

@interface MyViewController: UIViewController {

UIView *myView;

}

to

@interface MyViewController: UIViewController {

MyView *myView;

}
0

精彩评论

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