あるviewcontrollerからボタンによって2種類の追加したviewcontrollerに遷移したいです。そこで以下のコードを書きました。
func
1 let viewHeight = self.view.frame.height 2 let viewWidth = self.view.frame.width 3 let margin = viewHeight/5 4 var tab:UIButton! 5 var tabs:[UIButton] = [] 6 7 for i in 0..<3{ 8 //画像 9 tab = UIButton() 10 tab.frame = CGRect(x: CGFloat(i)*viewWidth/3, y: margin/2,width:viewWidth/3,height:margin/2) 11 tab.layer.borderColor = UIColor(red: 0.7, green: 0.2, blue: 0.2, alpha: 1.0).cgColor 12 tab.layer.borderWidth = 2.0 13 tab.tag = i 14 print(tab.tag) 15 self.view.addSubview(tab) 16 tabs.append(tab) 17 18 switch tab.tag { 19 case 0: 20 tabs[0].setTitle("Standard", for: .normal) 21 tab.backgroundColor = UIColor(red: 0.7, green: 0.2, blue: 0.2, alpha: 1.0) 22 case 1: 23 tabs[1].setTitle("Trap", for: .normal) 24 tab.backgroundColor = UIColor.gray 25 tabs[1].addTarget(self, action: #selector(RankingViewController.goTrap()), for: .touchUpInside) 26 default: 27 tabs[2].setTitle("Endless", for: .normal) 28 tab.backgroundColor = UIColor.gray 29 tabs[2].addTarget(self, action: #selector(RankingViewController.goEndless()), for: .touchUpInside) 30 } 31 } 32 33 34 35 } 36 37 @objc func goTrap(){ 38 let nextvc = TrapRankViewController() 39 nextvc.view.backgroundColor = UIColor.blue 40 self.present(nextvc, animated: true, completion: nil) 41 42 } 43 44 @objc func goEndless(){ 45 let nextvc = EndlessRankViewController() 46 nextvc.view.backgroundColor = UIColor.blue 47 self.present(nextvc, animated: true, completion: nil) 48 49 } 50
するとaddtargetのところにInstance member 'goTrap' cannot be used on type 'RankingViewController'; did you mean to use a value of this type instead?
というエラーが出ます。考えられる原因には何があるでしょうか。よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。