やりたいこと
コードでの画面遷移を実現したい。(少し複雑な)
ホーム画面で入力したしたデータを他のsceneに渡したい。
出来ていること
入力したデータは他のscnenには渡せている。
基本的な画面遷移は出来ている。
困っていること
他のsceneに渡したデータをtableViewに反映されない。
下記の2.[History]ボタンからの遷移がうまく出来ずに困っている。(tableviewにデータを渡せれてないのが原因だと思われる。)
- 1.ホーム画面scene
- 2.内容scene
- 3.内容を管理するscene
0. [start]ボタン 1 → 2
0. [History]ボタン 1 → 3 → 2
コード等は下記のリポジトリにあげています。
https://github.com/haruka22/project
追記
遷移先のtableViewにデータが反映されない
HistoryViewController.swift
1import UIKit 2 3class HistoryViewController: UIViewController,UITableViewDelegate,UITableViewDataSource{ 4 5 @IBOutlet weak var HistorytableView: UITableView! 6 7 8 var datetime = UILabel()//var datetime: UILabel! /オプショナル型はなるべく使わない 9 var nameitem = UILabel() 10 11 12 13 // ボタンを用意 14 var addBtn: UIBarButtonItem! 15 16 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 17 return 0 18 } 19 20 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 21 let cell = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) 22 cell.textLabel?.text = datetime.text 23 24 return cell 25 } 26 27 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 28 //セルの選択解除 29 tableView.deselectRow(at: indexPath, animated: true) 30 31 //ここに遷移処理を書く 32 self.present(ViewController(), animated: true, completion: nil) 33 } 34 35 36 37 override func viewDidLoad() { 38 super.viewDidLoad() 39 40 HistorytableView.delegate = self 41 HistorytableView.dataSource = self 42 HistorytableView.backgroundColor = UIColor.lightGray 43 self.navigationItem.title = "データベース" 44 HistorytableView.reloadData() 45 } 46 47 func onClick() { 48 print("ボタンがおされました") 49 let second = ViewController() 50 present(second, animated: true, completion: nil) 51 52 } 53 54}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/05/30 19:51