我的UITableView
有问题。最终,我希望它看起来像这样(白色矩形)。
如何设置.backgroundcolor
,使其清晰如图片所示?我遇到的另一个问题是我的TableView
被“预填充”为空的cells
。
我已经尝试过了,但是以某种方式不起作用:
[TableViewController
class
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 }
自定义
Cell
类
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) self.addSubview(checkButton) self.backgroundColor = .clear }
我如何创建我的
UITableView
let theTableView: WhishlistTableViewController = { let v = WhishlistTableViewController() v.view.layer.masksToBounds = true v.view.layer.borderColor = UIColor.white.cgColor v.view.backgroundColor = .clear v.view.layer.borderWidth = 2.0 v.view.translatesAutoresizingMaskIntoConstraints = false return v }()
我的
UITableView
的所有功能均正常工作。只是backgroundcolor
和空的cells
...
我非常感谢您的帮助:)我对此一无所获。。
我的UITableView有问题。最终,我希望它看起来像这样(白色矩形)。如何设置.backgroundcolor使其清晰可见(如图片所示)?我是另一个问题...
在您的WhishlistTableViewController
类中:
override func viewDidLoad() {
super.viewDidLoad()
// set background to clear
tableView.backgroundColor = .clear
// add clear view as tableFooterView
// to prevent empty cells
let v = UIView()
v.backgroundColor = .clear
tableView.tableFooterView = v
// ... rest of table setup
tableView.register(WishCell.self, forCellReuseIdentifier: "WishCell")
}