简体   繁体   中英

Display selected row data from UITableView in UIButton

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

Because you implement it in tableView: didDeselectRowAtIndexPath: , you should implement it in tableView: didSelectRowAtIndexPath: instead. Be careful with the names. :)

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM