我有自定義UITableViewCell
其中包含文本字段。問題出現在我在第一個文本字段中輸入一些文本後(例如)在滾動tableView後,此文本在另一個單元格中複製。我知道,這是因爲tableView出隊單元。
處理這個問題的正確方法是什麼?
我的代碼:
滾動tableview時複製數據查看
@IBOutlet weak var tableView: UITableView!
var dataArray: [String] = []
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
for i in 0...50 {
dataArray.append("Elemnt # \(i)")
}
}
}
extension ViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
return cell
}
謝謝。我會嘗試你的解決方案 – makedonskii