I am having troubles customizing my cells
inside my UITableView
. I would like to have a UIButton
on the left but somehow the UIButton
only appears inside the first cell
:
This is how I create the UIButton
inside my UITableViewCell
:
class WhishCell: UITableViewCell {
let checkButton: UIButton = {
let v = UIButton()
v.backgroundColor = .red
v.translatesAutoresizingMaskIntoConstraints = false
return v
}()
public static let reuseID = "WhishCell"
required init?(coder: NSCoder) {fatalError("init(coder:) has not been implemented")}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.addSubview(checkButton)
self.backgroundColor = .clear
}
}
My TableView
:
class WhishlistTableViewController: UITableViewController {
public var wishList = [Wish]()
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.allowsSelection = false
self.tableView.register(WhishCell.self, forCellReuseIdentifier: WhishCell.reuseID)
self.wishList.append(Wish(withWishName: "Test"))
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return wishList.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: WhishCell.reuseID, for: indexPath)
let currentWish = self.wishList[indexPath.row]
cell.textLabel?.text = currentWish.wishName
cell.backgroundColor = .clear
return cell
}
Does anyone know why it only appears only on the first cell
?? Kind of new to TableViews
so I'm happy with every help :)
ViewController
where I basically just callwhishlist.append