【发布时间】:2021-01-08 19:03:25
【问题描述】:
我正在尝试根据用户输入创建多个部分。 我能够做到这一点,但下一步是在该部分的末尾创建按钮。 但是,我们不知道最后一部分是什么,因为它取决于用户的请求。 它看起来像这样:
现在,我为按钮创建了另一个单元格,如下所示:
到目前为止,这是我的代码:
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()
}
我有另一个班级与所有出口挂钩。 在所有这些未知数量的部分之后,如何在一个部分中创建另一个按钮?
提前谢谢你
【问题讨论】:
标签: ios swift uitableview tableview sections