2010-09-22 94 views
1

我有一個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!!! 

爲什麼會發生這種情況,如果一切都是公開的?

感謝

回答

1

我不知道這是否是錯字或沒有,但有一個在您的代碼「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方法

+0

L的東西只是一個錯字,因爲我不得不簡化這裏發佈的代碼。公共的東西是因爲我需要從主代碼中訪問它的值......但是如果你說該屬性生成公共getter和setter,我將刪除它......謝謝。 – SpaceDog 2010-09-22 02:42:36

+0

如果L只是一個錯字,那麼這真的很奇怪,因爲如果編譯器無法看到你的公共變量,它仍然必須使用public getter和setter – vodkhang 2010-09-22 02:57:51

+0

thanksssssssssssss! – SpaceDog 2010-09-22 13:50:27

1

我猜你的代碼中有一些拼寫錯誤。

@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應該包含在您訪問變量的代碼中。