iphone - 不显示
问题描述:
我有一个UIImageView基于类(可以称之为CLASSA)使用一个CLASSB并宣布类似的东西...iphone - 不显示
@interface classA : UIImageView {
@public classB *mylabel;
}
@property (nonatomic, retain) classB *mylabel;
... @synthesize myLabel was put on its .m
B类被声明类似
公共属性@interface classB : UILabel {
@public UILabel *myCustomlabel;
}
@property (nonatomic, retain) classB *myCustomlabel;
... @synthesize myCustomlabel was put on its .m
现在我在主代码上。我创建了一个这样的对象
classA *myObject = [[classA alloc] init];
myObject.myLabel.myCustomLabel.text = @"Hi there";
// this last line fails. It says there's not myCustomLabel structure on myLabel!!!
为什么会发生这种情况,如果一切都是公开的?
感谢
答
我不知道这是否是错字或没有,但有一个在您的代码“L”和“L”之间的错误。很可能,这造成你的问题,因为你的“L”和“L”
@public classB *mylabel; // small "l"
@property (nonatomic, retain) classB *mylabel; // small "l"
... @synthesize myLabel was put on its .m // big "L"
@interface classB : UILabel {
@public UILabel *myCustomlabel; // small "l"
}
@property (nonatomic, retain) classB *myCustomlabel; // small "l"
... @synthesize myCustomlabel was put on its .m // small "l"
所以之间陷入困境,我想,为您的代码,当你调用myObject.myLabel
,它使用@属性的get和@synthesize,然后是下一个myCustomLabel,它没有找到像这样的任何(变量,属性+合成),所以它抱怨
通常,如果你已经声明@property + @synthesize,你不需要,应该' n有公共变量。 @property已经生成了公共的getter和setter方法
答
我猜你的代码中有一些拼写错误。
@interface classB:UILabel @public UILabel * myCustomlabel; }
@property(nonatomic,retain)classB * myCustomlabel; //类型应该是UILabel不是ClassB
classA * myObject = [[classA alloc] init]; myObject.myLabel.myCustomLabel.text = @“Hi there”; // myLable L应该很小
而且ClassA.h和classB.h应该包含在您访问变量的代码中。
L的东西只是一个错字,因为我不得不简化这里发布的代码。公共的东西是因为我需要从主代码中访问它的值......但是如果你说该属性生成公共getter和setter,我将删除它......谢谢。 – SpaceDog 2010-09-22 02:42:36
如果L只是一个错字,那么这真的很奇怪,因为如果编译器无法看到你的公共变量,它仍然必须使用public getter和setter – vodkhang 2010-09-22 02:57:51
thanksssssssssssss! – SpaceDog 2010-09-22 13:50:27