我的方法里创建这样一个按钮:iPhone - 方法之外的零按钮?
UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(0, 0, 100, 50);
[btn setTitle:@"Hello, world!" forState:UIControlStateNormal];
[self.view addSubview:btn];
myButton = btn;
// I am saving the btn reference to this ivar declared on .h as UIButton.
在我尝试使用myButton的代码的另一点,它始终是零。
我试图在原来的方法将其分配给myButton的后保留BTN但myButton为始终为零。
self.view始终存在。 btn从未发布。
为什么myButton是零?
我知道我可以创建一个使用ALLOC按钮,但我只是想了解这一点。
谢谢。
您可能正在寻找self.myButton = btn; – Rog 2010-12-08 06:31:32