Я создаю простое приложение, используя Swift 5, Xcode 11 и контроллер табличного представления пользовательского интерфейса. В представлении таблицы пользовательского интерфейса мне нужны 2 кнопки: одна кнопка слева от моего вида таблицы, другая справа. Я пробовал ответы на многие другие похожие / похожие вопросы, но все они не дали результатов (вероятно, потому что 1. Слишком старый, 2. Ответ, написанный на OBJ- C).
Вот мой контроллер табличного представления:
import UIKit
@objcMembers class CustomViewController: UITableViewController {
var tag = 0
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
}
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
// 3
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
tag = tag + 1
let cell = tableView.dequeueReusableCell(withIdentifier: "themeCell", for: indexPath) as! ThemeCell
var cellButton: UIButton!
cellButton = UIButton(frame: CGRect(x: 5, y: 5, width: 50, height: 30))
cell.addSubview(cellButton)
cell.img.image = UIImage(named: SingletonViewController.themes[indexPath.row])
cell.accessoryView = cellButton
cellButton.backgroundColor = UIColor.red
cellButton.tag = tag
return cell
}
}
Вот что я сейчас получаю: