Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 带有tag属性的UIButton_Iphone_Objective C_Uibutton - Fatal编程技术网

Iphone 带有tag属性的UIButton

Iphone 带有tag属性的UIButton,iphone,objective-c,uibutton,Iphone,Objective C,Uibutton,我正在通过使用获取带有标签托架名称的UIButton UIButton *mybutton=[[UIButton alloc]init]; mybutton=(UIButton*)[cell viewWithTag:5]; 和 UIButton*mybutton=(UIButton*)[带标记的单元格视图:5] 这很好,但是当我使用 [mybutton setTitle:@"hello" forState:UIControlStateNormal]; 应用程序因此错误而崩溃 [UITabl

我正在通过使用获取带有标签托架名称的UIButton

UIButton *mybutton=[[UIButton alloc]init];

mybutton=(UIButton*)[cell viewWithTag:5];
和 UIButton*mybutton=(UIButton*)[带标记的单元格视图:5]

这很好,但是当我使用

[mybutton setTitle:@"hello" forState:UIControlStateNormal];
应用程序因此错误而崩溃

[UITableViewCell setTitle:forState:]: unrecognized selector sent to instance 0x4b6f540'
*第一次抛出时调用堆栈:

有什么解决办法吗


提前感谢

与您的contentView一起使用

    mybutton=(UIButton*)[cell.contentView viewWithTag:5];

细胞本身似乎有标记5。确保按钮在要使用
viewWithTag:
方法搜索的视图层次结构中具有唯一的标记。如果您想要更高的分辨率,应该添加
tableView:cellforrowatinexpath:
方法。为什么要分配/初始化UIButton,然后将其设置为viewWithTag的结果?这将导致内存泄漏。如果您试图设置按钮的标签,只需执行
[mybutton setTag:5]这是正确的。将此标记为已回答。必须获取cell.contentView才能获取其子视图。