我创建了一个属性
@property (weak,nonatomic) UILabel *vishalSays;
然后我试图初始化属性,如下所示:
- (void)viewDidLoad
{
[super viewDidLoad];
self.vishalSays = [[UILabel alloc] initWithFrame:CGRectMake(30, 100, 200, 44)];
[self.vishalSays setText:@"Hello World"];
[self.view addSubview:self.vishalSays];
}
但是上面的代码在 iPhone 模拟器中没有显示标签。将代码更改为以下时:
- (void)viewDidLoad
{
[super viewDidLoad];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(30, 100, 200, 44)];
self.vishalSays = label;
[self.vishalSays setText:@"Hello World"];
[self.view addSubview:self.vishalSays];
}
然后“Hello World”标签变得可见。有人可以解释为什么这两种语法之间存在行为差异吗?谢谢维沙尔