【swift】 cellがタップされたときに詳細画面に遷移する【CoffeeNote開発メモ】
Segueで画面遷移
ここあたりを参考にさせていただいて,セルが押されたときにsegueで詳細画面に飛ぶように設定.
[Swift] TableViewのセルが選択され画面遷移する設定について
[iOS] StoryboardでUITableView+UINavigationControllerの詳細画面を作る [4月からはじめるiPhoneアプリ #4] | Developers.IO
// TableViewController.swift func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { performSegueWithIdentifier("toDetailViewController", sender: self) }
cellがタップされたときの処理はdidSelectRowAtIndexPathを使う.
AppDelegateで値の受け渡し
ここを参考に値の受け渡しをできるようにした.
SwiftでAppDelegateを使った画面間のデータ受け渡し - Qiita
まずAppDelegate内に受け渡ししたい変数を宣言.
// AppDelegate.swift var blendName: String?
値を渡す方で,値をいじる
// TableViewController.swift var appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate appDelegate.blendName = "HouseBlend"
そして受け取る
// DetailVirewController.swift var appDelegate:AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate var blendName = appDelegate.blendName