如何在表视图中的某些数据快速添加后添加另一个部分按钮?

问题描述

我正在尝试根据用户输入创建多个部分。 我能够做到,但是下一步是在本节末尾创建按钮。 但是,我们不知道最后一节是什么,因为这取决于用户的要求。 看起来像这样:

enter image description here

现在,我为按钮创建了另一个单元格,如下所示:

enter image description here

到目前为止,这是我的代码:

var numberOfSection: Int = 0 {
    didSet {
        tableView.reloadData()
    }
}

override func numberOfSections(in tableView: UITableView) -> Int {
    if numberOfSection == 0 {
        return 2
    }
    else if numberOfSection <= numberOfSection {
        return numberOfSection + 1
    }
    return numberOfSection + 1
}

override func tableView(_ tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
    if section == 0 {
        return 1
    }
    else if section <= numberOfSection + 1 {
        for _ in 0...numberOfSection {
            return testeSpec.count
        }
    }
    else {
        return 1
    }
    return 1
}

override func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let tableSection = indexPath.section
    if tableSection == 0 {
        let cells = tableView.dequeueReusableCell(withIdentifier: "serverNumbCell",for: indexPath) as! CellOutlet
        let txtFieldServerNumber = cells.txtFieldServerNumb
        cells.lblSectionNumb.text = "Number of section:"
        txtFieldServerNumber?.addTarget(self,action: #selector(sectionTxtFieldDidChange),for: .editingChanged)
        return cells
    }
    
    else if tableSection <= numberOfSection + 1 {
        for _ in 0...numberOfSection {
            let cells = tableView.dequeueReusableCell(withIdentifier: "serverSpecCell",for: indexPath) as! CellOutlet
            let specWS = testSpec[indexPath.row]
            cells.labels.text = specWS.spec
            return cells
        }
    }
    else {
        let cells = tableView.dequeueReusableCell(withIdentifier: "buttonCell",for: indexPath) as! CellOutlet
        cells.btnResult.setTitle("OK",for: .normal)
        return cells
    }
    return CellOutlet()
}

我还有另外一堂课与所有课程有关。 如何在所有未知数目的部分之后的部分中创建另一个按钮?

提前谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)