尝试在运行时添加动态按钮时,应用程序崩溃

时间:2016-09-10 08:19:20

标签: ios objective-c uibutton

我正在尝试在运行时添加按钮和标签。当我运行应用程序时,它每次都会崩溃。

这是代码

UIButton *btnDelete = [UIButton buttonWithType:UIButtonTypeRoundedRect];

btnDelete.frame = CGRectMake (lblName.frame.origin.x+lblName.frame.size.width+5, 2, 30, 30);

[btnDelete setTitle:@"X" forState:UIControlStateNormal];

[btnDelete addTarget:self action:@selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];

btnDelete.backgroundColor= [UIColor clearColor];

[view addSubview:btnDelete];

当我运行此代码时,第一个按钮成功添加,当我尝试添加另一个按钮应用程序崩溃并显示以下错误时:

*由于未捕获的异常终止应用' NSInvalidArgumentException',原因:' - [UIButton text]:无法识别的选择器发送到实例0x7a985cf0' * 首先抛出调用堆栈:

0 个答案:

没有答案