私はSwift 3の初心者です。私はテーブルビューを持っており、ユーザーはテーブルビューセルを削除できます。今私は、ユーザーがセルの内容を変更できるようにしたい。私は4つの名前( "Stremmel"、 "Emma"、 "Sam"、 "Daisy")を含む配列を持っていて、ユーザはStremmelをGeorgeに編集することができるようにしたい。
私はそうする方法を考えるのに役立つような文書や似たような質問を探しましたが、私はもっと混乱しました。誰か私に助けを提供してもらえますか?ありがとうございました。ここに私のテーブルビューは以下のとおりです。Swift 3のテーブルセルの内容を編集する方法
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()
}
}
最初に何を意味するのか尋ねることはできますか? (self.list [indexPath.row] = alert.textFields!.first!.text!) –
@ D.Moses AlertControllerには['textFields'](https://developer.apple.com/reference/uikit/uialertcontroller/)があります。 1620104-textfields)プロパティーには '[UItextField]'型があり、我々は 'textfields'配列の最初のプロパティーを使ってそれにアクセスしているので、警告のテキストフィールドが1つあります。 –
これは非常に役に立ちます。ご清聴ありがとうございます。 –