【问题标题】:Display selected row data from UITableView in UIButton在 UIButton 中显示从 UITableView 中选择的行数据
【发布时间】:2016-03-23 11:19:17
【问题描述】:

我编写这段代码是为了在UIButton 上显示来自UITableView 的选定项目。问题是 UIButton 标题在选择行时没有改变,但在单击另一个项目并将按钮的标签放在第一个选择后它会改变。

如何在点击UITableView 行时直接显示数据。

func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {

    countryButton.setTitle(names[indexPath.row], forState: UIControlState.Normal)
}

注意:names 是我的数组

【问题讨论】:

    标签: ios uitableview swift2


    【解决方案1】:

    因为您在tableView: didDeselectRowAtIndexPath: 中实现它,所以您应该在tableView: didSelectRowAtIndexPath: 中实现它。小心名字。 :)

    【讨论】:

    • 真的谢谢你 我没看到 :D
    【解决方案2】:
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    
        countryButton.setTitle(names[indexPath.row], forState: UIControlState.Normal)
    }
    

    【讨论】:

      猜你喜欢
      • 2015-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-10
      相关资源
      最近更新 更多