在我的概念中,tableview 的每一行都是一种您可以填写的任务。每次您打开应用程序时,tableview 上的一行应该是先验的。 (如图所示)
我还有一个按钮,可以让你添加一行。 但我不知道我怎么知道部分的行数。 你能帮我一下吗?(在我的代码中,我评论了我无法理解的时刻)
class TaskSecondViewController: UIViewController,UITableViewDataSource{
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
self.tableView.separatorColor = UIColor.clear
@IBAction func insert_rows(_ sender: Any) {
let indexPath = IndexPath(row: 1, section: 1) // Don't know what to write in "row"
self.tableView.insertRows(at: [indexPath], with: .top)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1 // Here also
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TaskTableViewCell
return cell
}
}
最佳答案
你试过这个吗:
yourTableView.numberOfRows(inSection: 0)
这将返回 TableView 部分中的行数
关于ios - 不知道部分中的行数(快速),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41107613/