【发布时间】:2018-02-19 08:15:33
【问题描述】:
我在 tableview 单元格上实现了一个不喜欢的按钮,但无法更改按钮的图像。任何人都可以帮助我使用 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
}
【问题讨论】:
-
您忘记添加有问题的代码
-
只是一个普通的表格视图和一个按钮。稍后我会将它实施到项目中。你能帮帮我吗? @迈克·阿尔特
-
查看@KavyaKavita 的答案并实施
-
请详细说明。你想在哪里更改图像。如果要使图像静态,请从 Storyboard 中更改它。否则使用 didSelectItemAt 方法
标签: ios swift xcode uitableview cocoa-touch