我有我的自定義UIButton類中的UIImageView和UILabel。UIImageView/UILabel屬性總是爲零,直接分配和分配
但是,如果我有如下代碼
self.productImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
self.productName = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 20)];
的self.productImage和self.productName永遠是零轉讓之後。
如果我使用一個臨時變量,然後分配給屬性,它工作得很好:
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
self.productImage = imgView;
UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 20)];
self.productName = name;
我新的Objective-C和我不知道這有什麼錯在第一次使用。任何建議,將不勝感激!
你在哪裏初始化標籤和形象?鑑於沒有加載? –
是的。它在viewDidLoad方法中 – xxris