swiftでサイドメニューを実装しようとしています。メニュー欄はtableviewにしたいのですが下記のコードを打ってもシミュレータには白いtableview(中身が何もない)が表示されてしまいます。データソースメソッドやセルを取得するコードを記入しているにも関わらず何も表示されません。自分では何が悪いのかわからないのでご存知の方御教授願います。
それが表示されたらTODO2に書いてあるサイトをブラウザで表示したいです。
よろしくお願いします。
swift
1import UIKit 2 3class MenuViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 4 5 let TODO2 = ["Youtube", "Buzzvideo", "Instagram","Twitter","ニコニコ動画","FC2動画","Google"] 6 7 @IBOutlet weak var menuView: UITableView! 8 9 override func viewDidLoad() { 10 super.viewDidLoad() 11 12 // Do any additional setup after loading the view. 13 } 14 15 override func didReceiveMemoryWarning() { 16 super.didReceiveMemoryWarning() 17 // Dispose of any resources that can be recreated. 18 } 19 20 override func viewWillAppear(_ animated: Bool) 21 { 22 super.viewWillAppear(animated) 23 24 let menuPos = self.menuView.layer.position 25 self.menuView.layer.position.x = -self.menuView.frame.width 26 UIView.animate( 27 withDuration: 0.5, 28 delay: 0, 29 options: .curveEaseOut, 30 animations: { 31 self.menuView.layer.position.x = menuPos.x 32 }, 33 completion: { bool in}) 34 } 35 36 override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) 37 { 38 super.touchesEnded(touches, with: event) 39 for touch in touches 40 { 41 if touch.view?.tag == 1 42 { 43 UIView.animate(withDuration: 0.2, 44 delay: 0, 45 options: .curveEaseIn, 46 animations: 47 { 48 self.menuView.layer.position.x = -self.menuView.frame.width 49 }, 50 completion: 51 { 52 bool in self.dismiss(animated: true, completion: nil) 53 } 54 ) 55 } 56 } 57 } 58 59 60 61 //追加③ セルの個数を指定するデリゲートメソッド(必須) 62 func tableView(_ menuView: UITableView, numberOfRowsInSection section: Int) -> Int { 63 return TODO2.count 64 } 65 66 //追加④ セルに値を設定するデータソースメソッド(必須) 67 func tableView(_ menuView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 68 // セルを取得する 69 let cell: UITableViewCell = menuView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) 70 // セルに表示する値を設定する 71 cell.textLabel!.text = TODO2[indexPath.row] 72 return cell 73 } 74} 75
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/20 06:34