gpt4 book ai didi

ios - 以编程方式快速创建 uitableview 而不是加载

转载 作者:技术小花猫 更新时间:2023-10-29 11:17:30 24 4
gpt4 key购买 nike

我正在尝试以编程方式在 swift 中创建一个 uitableview,但这里没有加载是我的代码:

class ViewController: UIViewController, UITableViewDelegate,UITableViewDataSource {
var tableView: UITableView = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
self.view.addSubview(self.tableView)
}

你们中有人知道我遗漏了什么或我的代码有什么问题吗?

非常感谢您的帮助。

最佳答案

override func viewDidLoad() {
super.viewDidLoad()
tableView = UITableView(frame: UIScreen.mainScreen().bounds, style: UITableViewStyle.Plain)
tableView.delegate = self
tableView.dataSource = self
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
self.view.addSubview(self.tableView)
}

tableView = UITableView(frame: UIScreen.mainScreen().bounds, style: UITableViewStyle.Plain)

这行代码将设置您的tableview 的框架,以及默认的UITableViewStyle

关于ios - 以编程方式快速创建 uitableview 而不是加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32708239/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com