swift
1import UIKit 2 3class MenuViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 4 5 let TODO2 = ["Youtube", "Buzzvideo", "Instagram","Twitter","ニコニコ動画","FC2動画","Google"] 6 let parameters = ["Youtube": "Buzzvideo", "Instagram": "Twitter","ニコニコ動画":"FC2動画"] 7 8 @IBOutlet weak var menuView: UITableView! 9 10 override func viewDidLoad() { 11 super.viewDidLoad() 12 } 13 14 func segueToFirstViewController() { 15 self.performSegue(withIdentifier: "toFirstViewController", sender: self.parameters) 16 } 17 18 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 19 if segue.identifier == "toFirstViewController" { 20 let MenuViewController = segue.destination as! MenuViewController 21 FirstViewController.parameters = sender as! [String : String] 22 } 23 24 menuView.delegate = self 25 menuView.dataSource = self 26 } 27 28 override func didReceiveMemoryWarning() { 29 super.didReceiveMemoryWarning() 30 // Dispose of any resources that can be recreated. 31 } 32 33 override func viewWillAppear(_ animated: Bool) 34 { 35 super.viewWillAppear(animated) 36 37 let menuPos = self.menuView.layer.position 38 self.menuView.layer.position.x = -self.menuView.frame.width 39 UIView.animate( 40 withDuration: 0.5, 41 delay: 0, 42 options: .curveEaseOut, 43 animations: { 44 self.menuView.layer.position.x = menuPos.x 45 }, 46 completion: { bool in}) 47 } 48 49 override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) 50 { 51 super.touchesEnded(touches, with: event) 52 for touch in touches 53 { 54 if touch.view?.tag == 1 55 { 56 UIView.animate(withDuration: 0.2, 57 delay: 0, 58 options: .curveEaseIn, 59 animations: 60 { 61 self.menuView.layer.position.x = -self.menuView.frame.width 62 }, 63 completion: 64 { 65 bool in self.dismiss(animated: true, completion: nil) 66 } 67 ) 68 } 69 } 70 } 71 72 73 74 //追加③ セルの個数を指定するデリゲートメソッド(必須) 75 func tableView(_ menuView: UITableView, numberOfRowsInSection section: Int) -> Int { 76 return TODO2.count 77 } 78 79 //追加④ セルに値を設定するデータソースメソッド(必須) 80 func tableView(_ menuView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 81 // セルを取得する 82 let cell: UITableViewCell = menuView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) 83 // セルに表示する値を設定する 84 cell.textLabel!.text = TODO2[indexPath.row] 85 return cell 86 } 87} 88```![![イメージ説明](29962e4f601365878a6e210eff9728d7.png)] 89> 上記の写真のようにサイドメニューから各サービスをブラウザで開きたいのですがtableviewは最初に表示するFirstViewControllerではなく専用のMenuViewControllerで繋いでるのでどこに画面移行するコードを持って行ってよいかわかりません。どなたか教えていただけると嬉しいです。説明不足や意味不明と言う場合も返信を下されば説明し直します。どうかよろしくお願いします。
サイドメニューがあるMenuViewControllerからどうやってWKWebvIewのあるFirstViewControllerにブラウザを表示するか聞きたいです。
回答2件
あなたの回答
tips
プレビュー