我的自定义 UIButton 类中有一个 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 将始终为 nil。
如果我使用临时变量然后分配给属性,它工作得很好:
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 的新手,我不知道第一次使用有什么问题。任何建议,将不胜感激!