我有我的自定义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