小编D.M*_*ses的帖子

如何在Swift 3中编辑表格单元格的内容

我是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)

ios swift swift3

3
推荐指数
1
解决办法
8453
查看次数

标签 统计

ios ×1

swift ×1

swift3 ×1