Tableviewのcellのうち、1を押したら1をUserdefaultsに、2を押したら2をUserdefaultsに保存したいです。どこにどんなコードを書けば良いのでしょうか。教えてください。
swift
1import UIKit 2 3class set: UIViewController,UITableViewDelegate, UITableViewDataSource { 4 5 var data = ["1", "2", "3"] 6 7 @IBOutlet weak var table: UITableView! 8 override func viewDidLoad() { 9 super.viewDidLoad() 10 // Do any additional setup after loading the view. 11 table.delegate = self 12 table.dataSource = self 13 } 14 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 15 return data.count 16 } 17 18 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 19 // セルの型を作る 20 let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "myCell") 21 // セルに表示するテキストを作る 22 cell.textLabel?.text = data[indexPath.row] 23 // セルをリターンする 24 return cell 25 } 26 27} 28
回答2件
あなたの回答
tips
プレビュー