gpt4 book ai didi

ios - 如何在代码中使用 UItable 单元格中的按钮导出

转载 作者:行者123 更新时间:2023-11-30 14:12:55 26 4
gpt4 key购买 nike

我正在尝试在 UITableViewController 内的每个 UITable 单元格中创建一个按钮。我在我的 Storyboard中的单元格中放置了一个按钮,但是当我尝试在我的 swift 文件中创建一个 socket 时,我收到一条错误消息:“非法配置:从 GroupNamesTable 到 UIButton 的按钮 socket 无效。 socket 无法连接到重复的内容。”如何将 Storyboard中的按钮集成到实际的 swift 文件中?如有任何建议,我们将不胜感激。

class GroupNamesTable: UITableViewController {
@IBOutlet var Buttons: UIButton!
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellidentifier, forIndexPath: indexPath) as! UITableViewCell
let joinbutton: UIButton = Buttons
joinbutton.addTarget(self, action: "print", forControlEvents: UIControlEvents.TouchUpInside)
cell.addSubview(joinbutton)
return cell
}
}

最佳答案

我想使用cell.contentView.subview[]来获取UIButton。由于您的按钮已位于 Storyboard 中,因此索引是固定的。然后使用addTarget添加 Action 。

enter image description here enter image description here

代码

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell : UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell
var btn : UIButton = cell.contentView.subviews[0] as! UIButton
btn.addTarget(<#target: AnyObject?#>, action: <#Selector#>, forControlEvents: <#UIControlEvents#>)
return cell
}

关于ios - 如何在代码中使用 UItable 单元格中的按钮导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31551799/

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