我在桌面视图单元上实现了一个喜欢不喜欢的按钮,但无法更改按钮的图像。任何人可以帮助我使用SWIFT 3如何在tableVIewCell上选中时更改UIButton的图像。在Swift 3
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
var array: [String] = ["A","B","C","D","E","F"]
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return array.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: cell_TableTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: "cell_TableTableViewCell") as UITableViewCell! as! cell_TableTableViewCell!
cell.textLabel?.text = array[indexPath.row]
cell.button_Outlet.tag = indexPath.row
cell.button_Outlet.addTarget(self, action: "LikePressed", for: .touchUpInside)
return cell
}
}
func LikePressed(sender : UIButton){
sender.isSelected = !sender.isSelected
}
你忘了有问题 –
添加代码只是一个正常表单视图和一个按钮,稍后我会将它实现到项目中,可以帮助我@Mike Alter –
查看@KavyaKavita的答案并执行它 –