ios - 不知道部分中的行数(快速)

标签 ios swift uitableview

在我的概念中,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/

相关文章:

ios - UIPrintInteractionController (Swift) 最多可以执行多少次打印?

ios - 在 Swift 中将 UILabel 的一部分设为粗体

ios - 如何动态更改 UITableView 中单元格的高度?

iphone - 如何摆脱粘滞的 iPad 启动画面?

ios - 维护 RKObjectManager/AFHTTPClient 请求排序

swift - 两个不同模块中的相同类扩展

ios - 具有分组表问题的 commitEditingStyle

iphone - 更改为 NSFetchedResultsController 后 UITableView 未更新数据源

ios - Firebase 远程配置返回 0(Swift iOS)

ios - 每秒运行一个 NSTimer 会有多费力?