在UIButton

时间:2016-03-23 11:19:18

标签: ios uitableview swift2

我编写此代码以显示UITableViewUIButton的所选项目。问题是UIButton标题在选择行时没有改变,但是在点击另一个项目并且为第一个选择放置按钮标签后它会发生变化。

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

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

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

注意:名字是我的数组

2 个答案:

答案 0 :(得分:2)

由于您是在tableView: didDeselectRowAtIndexPath:中实施的,因此您应该在tableView: didSelectRowAtIndexPath:中实施它。小心这些名字。 :)

答案 1 :(得分:1)

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

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