我是Swift 3的初学者.我有一个表视图,用户可以删除表视图单元格.现在我希望用户能够更改单元格的内容.我有一个包含四个名字的数组["Stremmel","Emma","Sam","Daisy"],我希望用户能够说Stremmel到George.
我搜索了文档或类似的问题,可以帮助我找到一种方法,但我更困惑.有人可以请我帮忙!! 谢谢.这是我的表格视图:
import UIKit
var list = ["Stremmel" , "Emma" , "Sam" , "Daisy"]
class ViewController: UITableViewController {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return list.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.textLabel?.text = list[indexPath.row]
return cell
}
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == UITableViewCellEditingStyle.delete
{
list.remove(at: indexPath.row)
tableView.reloadData()
}
}
Run Code Online (Sandbox Code Playgroud)