1
我創建了一個屬性的UILabel是沒有得到初始化
@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」標籤變爲可見。有人可以解釋爲什麼兩種語法之間存在行爲差異? 謝謝 Vishal
感謝很多來闡明。 –