前提・実現したいこと
セルをタップ → セルの中身をcontainerviewのラベルに表示
ContainerViewにtableViewのデータを渡したいです。
今までは画面遷移の際はsegueを利用して行っていたので
performSegueでデータを渡していましたが、今回はそれではできないため困っています。
セグエを利用しないデータの引き渡しで調べましたが、行き詰まっています。
教えていただければ幸いです。どうぞよろしくお願いします。
該当のソースコード
import UIKit let kansaiList1 = [(title: "0", items: ["ねずみ", "うし", "とら", "うさぎ", "りゅう","おおかみ"]), (title: "1", items: ["へび", "うま","ひつじ","さる","とり","いぬ","いのしし","ねこ","しまうま"]), (title: "2", items: ["やぎ","くま","しろくま","こぶら","ごりら","ぶた","ぞう","おおかみ"]), ] var tableSection1 = 0 var tableRow1 = 0 class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet var tableView: UITableView! override func viewDidLoad() { super.viewDidLoad() tableView.delegate = self tableView.dataSource = self } //セクションの数返す func numberOfSections(in tableView: UITableView) -> Int { return kansaiList1.count } // セクションのタイトルを返す。 func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return kansaiList1[section].title } //セルの数を返す func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return kansaiList1[section].items.count } //セルに値を設定する func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // セルを取得する let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) // セルに表示する値を設定する cell.textLabel!.text = kansaiList1[indexPath.section].items[indexPath.row] return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { //ここでそれっぽいことを調べてコピペしたがわからない //let storyboard: UIStoryboard = self.storyboard! //let nextView = storyboard.instantiateInitialViewController() as! ContainerView tableSection1 = indexPath.section tableRow1 = indexPath.row } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } } _______________________________________________________________________________________ //遷移先のView import UIKit class ContainerView: UIViewController { @IBOutlet var kansaiLabel: UILabel! override func viewDidLoad() { super.viewDidLoad() kansaiLabel.text = kansaiList1[tableSection1].items[tableRow1] } }