###前提・実現したいこと
AppDelegateを使わないでViewControllerのindexPath.rowをNextViewControllerに渡したい__イタリックテキスト__
###発生している問題・エラーメッセージ
nextViewControllerのnum:Intでnilしか表示されない
###該当のソースコード
Swift
1class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 2 var num :Int = 0 3 let vc:NextViewController = NextViewController() 4} 5func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 6 7 num = indexPath.row 8 vc.num = num 9 10 tableView.deselectRow(at: indexPath, animated: true) 11 self.present(NextViewController(), animated: true, completion: nil) 12 13 } 14
class NextViewController: UIViewController { var num:Int? var label :UILabel = UILabel() override func viewDidLoad() { super.viewDidLoad() label.text = "(String(describing: num))"
###試したこと
これだと、nextViewControllerのnum:Int?でnilしか表示されない
ViewControllerのindexPath.rowを表示させたい
###補足情報(言語/FW/ツール等のバージョンなど)
swift4
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/23 23:29