embed inでnavigation controllerを設置し、titleの個所をクリックしてもedit出来ないと思っていたら、attribute inspectorのNavigation itemで編集出来ますね。
これだけにずっと悩んでいた
IndexPathSelectedRow
@IBAction func unwindToMemoList(sender: UIStoryboardSegue) { guard let sourceVC = sender.source as? memoViewController, let memo = sourceVC.memo else { return } if let selectedIndexPath = self.tableView.indexPathForSelectedRow { self.memos[selectedIndexPath.row] = memo } else { self.memos.append(memo) } self.tableView.reloadData() }
tableView.reloadDataでtableviewを表示
うーむ、windowsでudacityのiosコースのコードをなぞっていたのは全く時間の無駄だったな。
tableViewController からeditTextに値をわたす
override func viewDidLoad() { super.viewDidLoad() self.saveButton.isEnabled = false if let memo = self.memo { self.memoTextField.text = memo } // Do any additional setup after loading the view. }
キャンセルを実行する
@IBAction func cancel(_ sender: Any) { if self.presentingViewController is UINavigationController { self.dismiss(animated: true, completion: nil) } else { self.navigationController?.popViewController(animated: true) } }
お
スワイプしてtableviewを削除
tableviewcontrollerのコメントをはずす
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { // Delete the row from the data source self.memos.remove(at: indexPath.row) tableView.deleteRows(at: [indexPath], with: .fade) } else if editingStyle == .insert { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view } }
おおお、すげー
機能ありすぎて整理出来んな
メモを追加
var memo: String? @IBOutlet weak var memoTextField: UITextField! @IBOutlet weak var saveButton: UIBarButtonItem! override func viewDidLoad() { super.viewDidLoad() self.saveButton.isEnabled = false // Do any additional setup after loading the view. } @IBAction func memoTextFieldChanged(_ sender: Any) { let memo = self.memoTextField.text ?? "" self.saveButton.isEnabled = !memo.isEmpty } @IBAction func cancel(_ sender: Any) { self.dismiss(animated: true, completion: nil) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { guard let button = sender as? UIBarButtonItem, button === self.saveButton else{ return } self.memo = self.memoTextField.text ?? "" }
oh my goodness
i dont understand whats going on
tableViewControllerの配列に追加していく
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { guard let button = sender as? UIBarButtonItem, button === self.saveButton else{ return } self.memo = self.memoTextField.text ?? "" }
なに?
なんのこっちゃ…
どうしよう、これ
Navigation Controllerとは
Navigation Controllerとは、ページ上部にナビゲーションバーを表示し、複数画面を階層的に移動できるようにする部品。ナビゲーションバーや前画面に戻るためのボタンが自動表示
TableViewでtitleと詳細
var memos = [ ["title":"t1", "detail":"d1"], ["title":"t2", "detail":"d2"], ["title":"t3", "detail":"d3"] ] override func numberOfSections(in tableView: UITableView) -> Int { // #warning Incomplete implementation, return the number of sections return 1 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // #warning Incomplete implementation, return the number of rows return self.memos.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "MemoTableViewCell", for: indexPath) // Configure the cell... cell.textLabel?.text = self.memos[indexPath.row]["title"] cell.detailTextLabel?.text = self.memos[indexPath.row]["detail"] return cell }
TableViewControllerにoverrideしたtable section
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return "section-\(section)" }
エミュレーターに反映される時とされない時があるな。。
indexPath.section
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "MemoTableViewCell", for: indexPath) // Configure the cell... cell.textLabel?.text = self.memos[indexPath.section][indexPath.row] return cell }