【发布时间】:2019-05-27 09:41:36
【问题描述】:
我有表格视图,其中单元格由多个部分组成,每个部分有不同的行数,每行都有一个文本字段。当我在其中写入并向下和向上滚动时,数据丢失或重新排列。所以我试图将文本字段数据保存到二维数组中,但我无法解决这个问题。
这是自定义单元格中的代码:
class CustomCell: UITableViewCell {
@IBOutlet weak var userName: UITextField!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
查看控制器代码:
extension ViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let label = UILabel()
label.text = "Header"
return label
}
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 7
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableview.dequeueReusableCell(withIdentifier: CustomCell.identifier, for: indexPath) as! CustomCell
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 80.0
}
}
【问题讨论】:
标签: ios iphone swift uitableview uiscrollview