gpt4 book ai didi

ios - 在自定义 UITableView 中--类型 'AnyObject->()' 的值没有成员 'tag' 错误

转载 作者:行者123 更新时间:2023-11-28 11:13:16 25 4
gpt4 key购买 nike

我在制作自定义 UITableViewCell 时遇到问题。

问题是,在我的自定义类中,我的按钮代码带有发件人“AnyObject”:

@IBAction func checkBox(sender: AnyObject) {
}

在我的主 ViewController 中,我有更改单元格中某些内容的功能:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell:ingredientCell = self.ingredientTable.dequeueReusableCellWithIdentifier("cell") as! ingredientCell

cell.inCellLabel.text = self.items[indexPath.row]
cell.checkBox.tag = indexPath.row
cell.checkBox.addTarget(self, action: Selector("yourButtonClicked:"), forControlEvents: .TouchUpInside)

return cell
}

Xcode 在我的 cell.checkBox.tag 和 cell.checkBox.addTarget 行中说 Value of type 'AnyObject->()'has no member 'tag' 我真的无法理解,也找不到任何解决方案。

谢谢。

最佳答案

checkBox 是一个函数,您将其视为一个属性。如果您想要引用您的 checkBox View ,无论它是什么,您都需要为其创建一个 @IBOutlet 属性,该属性在 Storyboard 中连接并使用它而不是你的 @IBAction 函数。

代替

@IBAction func checkBox(sender: AnyObject) {}

你需要

@IBOutlet weak var checkBox: UIButton!

关于ios - 在自定义 UITableView 中--类型 'AnyObject->()' 的值没有成员 'tag' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33662020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com