我在桌面視圖單元上實現了一個喜歡不喜歡的按鈕,但無法更改按鈕的圖像。任何人可以幫助我使用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的答案並執行它 –