Reputation: 419
I wrote this code to display the selected item from UITableView
on UIButton
. The problem is that UIButton
title is not changing on selecting row but it changes after clicking on another item and put the label of button for the first selection.
How can I directly display the data on a click ot a UITableView
row.
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
countryButton.setTitle(names[indexPath.row], forState: UIControlState.Normal)
}
Note : names is my array
Upvotes: 0
Views: 91
Reputation: 643
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
countryButton.setTitle(names[indexPath.row], forState: UIControlState.Normal)
}
Upvotes: 1
Reputation: 354
Because you implement it in tableView: didDeselectRowAtIndexPath:
, you should implement it in tableView: didSelectRowAtIndexPath:
instead. Be careful with the names. :)
Upvotes: 2