gpt4 book ai didi

ios - UITableViewCell IBAction 在 iOS 7 中不起作用

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

我面临的问题是我用 Swift 开发了代码。它有一些自定义单元格和 UIButtons。这些按钮是 IBOutlet 连接,在它们各自的单元格中具有属性,并且针对它们的操作绑定(bind)在相同的类中。现在的问题是它在 iOS 8 中完美运行。但是我不知道每当我触摸按钮时 iOS 7 有什么问题,点击整个单元格并调用 Tableview 的 didSelectRowAtIndexPath:。到目前为止我所做的是

  • 检查父 View 和单元格的 .userInteractionEabled 并更改其值
  • 删除按钮并重新添加在不同论坛上找到的按钮,但没有成功
  • 检查了 Tableview 的委托(delegate)方法 numberOfSectionsnumberOfRowsInsection:heightForRowAtIndexPath: 并将它们的返回类型更改为 NSInteger 和 CGFloat,如在 stackoverflow 上找到的那样问题。

到目前为止还有其他人遇到过这个问题并找到了解决方案吗?

编辑

  • 在为单元格设置值后通过重置 UIButton 的目标操作进行检查。运气不好

最佳答案

我已经测试了你的问题。它对我来说运行良好。请在下面查看我的代码。

在 TestTableViewController.swift

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

let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as CustomCell

// Configure the cell...

cell.testButton.addTarget(cell, action: "testButtonClicked", forControlEvents: UIControlEvents.TouchUpInside)

return cell

}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

NSLog("didSelectRowAtIndexPath called")

}

在 CustomCell.swift 中

class CustomCell: UITableViewCell {

@IBOutlet var testButton: UIButton!

override func awakeFromNib() {

super.awakeFromNib()

// Initialization code

}

override func setSelected(selected: Bool, animated: Bool) {

super.setSelected(selected, animated: animated)

// Configure the view for the selected state

}

func testButtonClicked() {

NSLog("Button Clicked")

}

}

当我单击按钮时,它会记录“已单击按钮”,当单击单元格时,它会记录“didSelectRowAtIndexPath Called”。您可能在 reset() 函数或倒数第二个函数中做错了什么。

关于ios - UITableViewCell IBAction 在 iOS 7 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27597912/

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