开发者

iphone - setting a property on another class

I have a property declared on a class:

.h

@interface myClass : UIView {
  BOOL doStuff;
}

@property BOOL doStuff;

.m

@synthesize doStuff;

this class is a delegate of another one. On the other class开发者_运维技巧, I am trying to set this property, doing something like

[delegate setDoStuff:YES];

I receive an error telling me that "method -setDoStuff: not found..."

How do I declare the property on the class, so other classes can read and set them?

thanks.


is your delegate declared as type "id" ?
either you declare its true type MyClass delegate in the other class (which points to your myclass) or
declare a protocol that delegate has to implement id in declaration.
Last (but not right approach) is to typecast it [(MyClass
)delegate doStuff].


Make sure that you’re importing your custom class’s header and that delegate is declared as an instance of that class.


you could also specify the name of setter function in @property.

@property (nonatomic,setter = setMyDoStuff,assign) BOOL doStuff;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜