Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.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
Ios 无法设置带有标记的按钮_Ios_Xcode_Swift_Button_Tags - Fatal编程技术网

Ios 无法设置带有标记的按钮

Ios 无法设置带有标记的按钮,ios,xcode,swift,button,tags,Ios,Xcode,Swift,Button,Tags,我有一个单元格,我想使用,我只想在单元格中的按钮插座,这样我可以显示一个下拉菜单。我正试图用这个代码制作一个带有标签的按钮 var dropdownButton: UIButton = (PostCell.viewWithTag(200) as! UIButton) 我在cellForRowAtIndexPath中使用了它,但问题是我一直在说一个错误 “在“UIView”类型上使用实例成员“viewWithTag”;您是否打算改为使用“UIView”类型的值?尝试将代码用作 var dropd

我有一个单元格,我想使用,我只想在单元格中的按钮插座,这样我可以显示一个下拉菜单。我正试图用这个代码制作一个带有标签的按钮

var dropdownButton: UIButton = (PostCell.viewWithTag(200) as! UIButton)
我在cellForRowAtIndexPath中使用了它,但问题是我一直在说一个错误

“在“UIView”类型上使用实例成员“viewWithTag”;您是否打算改为使用“UIView”类型的值?

尝试将代码用作

var dropdownButton: UIButton = (postCell.contentView.viewWithTag(200) as? UIButton)
您正在使用的
PostCell
似乎是通过类名直接访问它。请尝试使用
UITableViewCell
的对象进行访问。
UITableViewCell
上的所有视图都放在其contentView上,因此可以从那里访问按钮

还可以使用
将对象获取为按钮,因为如果您使用
由于某种原因未找到标记200的对象,应用程序可能会崩溃


要防止应用程序崩溃,请使用

viewWIthTag是一种可用于UIVIew类型对象的方法。POSTCell不是UIVIew。