我以编程方式创建了一个带有两个 UIButton 的简单 iPhone 屏幕,如下所示。
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *buttonOne = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonOne.frame = CGRectMake(60, 70, 200, 40);
[buttonOne setTitle:@"One" forState:UIControlStateNormal];
[self.view addSubview:buttonOne];
UIButton *buttonTwo = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonTwo.frame = CGRectMake(60, 250, 200, 40);
[buttonTwo setTitle:@"Two" forState:UIControlStateNormal];
[self.view addSubview:buttonTwo];
}
现在按下标题为“One”的按钮时,我想将变量名设为“buttonOne”,类似地按下标题为“Two”的按钮时,我想将变量名设为“buttonTwo”。
我没有找到获取变量名的方法。有什么帮助吗?提前致谢