前提・実現したいこと
複数のピッカーを表示させたいのですがピッカーの行数に関するデリゲートとピッカーの最初の表示に関するデリゲートの部分にエラーが出てしまいます。どうしたら良いか教えていただけると幸いです
発生している問題・エラーメッセージ
Missing return in a function expected to return 'Int' Missing return in a function expected to return 'String?'
該当のソースコード
import UIKit class ChangeViewController: UIViewController, UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource{ var CLname: UITextField!//授業名 var CLgroup: UITextField!//分類選択ピッカー表示テキストフィールド var CLgroupPicker: UIPickerView!//授業分類ピッカー var CLtani: UITextField!//単位数表示テキストフィールド var CLteacher: UITextField!//教授名表示テキストフィールド var CLnumber: UITextField!//教室名表示テキストフィールド var CLzoomid: UITextField!//zoom ID表示テキストフィールド var CLzoompw: UITextField!//zoom PW表示テキストフィールド var HyoukaPicker: UIPickerView!//成績評価方法ピッカー var Hyouka : UITextField!//成績評価法表示テキストフィールド let grouplist : [String] = ["自学科科目(必修)","自学科科目(選択必修)","自学科科目","総合教養科目","キリスト教学","外国語科目","情報処理科目","自由選択科目","その他"] let Hyoukalist : [String] = ["平常点","期末試験","期末課題","授業内試験","通常課題","小テスト","その他"] var ToolBar : UIToolbar!//ピッカーツールバー override func viewDidLoad() { super.viewDidLoad() let navBar = UINavigationBar()//ナビゲーションバー navBar.frame = CGRect(x: 0,y: 50,width: 415,height: 60) let navItem : UINavigationItem = UINavigationItem(title: "月曜1限") navItem.leftBarButtonItem = UIBarButtonItem(title: "戻る",style: UIBarButtonItem.Style.plain, target: self, action: #selector(ChangeViewController.backbutton)) navBar.pushItem(navItem, animated: true) self.view.addSubview(navBar) let click = UIButton()//変更ボタン click.frame = CGRect(x:180, y:800, width: 100,height: 50) click.setTitle("変更", for: .normal) click.backgroundColor = UIColor.purple click.addTarget(self, action: #selector(ChangeViewController.changeButton), for: .touchUpInside) view.addSubview(click) CLname = UITextField()//授業名 CLname.delegate = self CLname.frame = CGRect(x: 50,y: 150,width: 300,height: 50) CLname.placeholder = "授業名" CLname.layer.borderColor = UIColor.lightGray.cgColor CLname.keyboardType = .default CLname.borderStyle = .roundedRect CLname.returnKeyType = .done self.view.addSubview(CLname) CLgroupPicker = UIPickerView()//分類ピッカー CLgroupPicker.frame = CGRect(x: 80,y: 200,width: self.view.frame.width, height: 300) CLgroupPicker.delegate = self CLgroupPicker.dataSource = self CLgroupPicker.tag = 1 ToolBar = UIToolbar(frame: CGRect(x:0,y: self.view.frame.size.height/6,width: self.view.frame.size.width,height: 40))//ツールバー作成 ToolBar.layer.position = CGPoint(x: self.view.frame.size.width/2,y: self.view.frame.size.height-20) let ToolBarButton = UIBarButtonItem(title: "完了", style: .done, target: self, action: #selector(self.onClick)) let spaceItem = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil) ToolBar.items = [spaceItem,ToolBarButton] CLgroup = UITextField()//分類ピッカー結果表示 CLgroup.delegate = self CLgroup.placeholder = "分類" CLgroup.borderStyle = .roundedRect CLgroup.frame = CGRect(x: 50,y: 240,width: 200,height: 50) CLgroup.textAlignment = NSTextAlignment.center CLgroup.layer.borderColor = UIColor.lightGray.cgColor CLgroup.layer.borderWidth = 1 CLgroup.inputView = CLgroupPicker CLgroup.inputAccessoryView = ToolBar self.view.addSubview(CLgroup) CLtani = UITextField()//単位数 CLtani.delegate = self CLtani.frame = CGRect(x: 280,y: 240,width: 80,height: 50) CLtani.placeholder = "単位数" CLtani.keyboardType = .default CLtani.borderStyle = .roundedRect CLtani.returnKeyType = .done self.view.addSubview(CLtani) CLteacher = UITextField() CLteacher.delegate = self CLteacher.frame = CGRect(x: 50,y: 330,width: 180,height: 50) CLteacher.placeholder = "教授名" CLteacher.keyboardType = .default CLteacher.borderStyle = .roundedRect CLteacher.returnKeyType = .done self.view.addSubview(CLteacher) CLnumber = UITextField()//教室名 CLnumber.delegate = self CLnumber.frame = CGRect(x: 50,y: 420,width: 90,height: 50) CLnumber.placeholder = "教室番号" CLnumber.keyboardType = .default CLnumber.borderStyle = .roundedRect CLnumber.returnKeyType = .done self.view.addSubview(CLnumber) CLzoomid = UITextField()//ZOOM ID CLzoomid.delegate = self CLzoomid.frame = CGRect(x: 50,y: 510,width: 150,height: 40) CLzoomid.placeholder = "ZoomID" CLzoomid.keyboardType = .default CLzoomid.returnKeyType = .done CLzoomid.borderStyle = .roundedRect self.view.addSubview(CLzoomid) CLzoompw = UITextField() CLzoompw.delegate = self CLzoompw.frame = CGRect(x: 210,y: 510, width: 150,height: 40) CLzoompw.placeholder = "ZOOM PW" CLzoompw.keyboardType = .default CLzoompw.returnKeyType = .done CLzoompw.borderStyle = .roundedRect self.view.addSubview(CLzoompw) HyoukaPicker = UIPickerView()//成績評価法ピッカー HyoukaPicker.frame = CGRect(x: 80,y: 200,width: self.view.frame.width, height: 300) HyoukaPicker.delegate = self HyoukaPicker.dataSource = self HyoukaPicker.tag = 2 Hyouka = UITextField()//成績評価法表示テキストフィールド Hyouka.delegate = self Hyouka.frame = CGRect(x: 50,y: 590,width: 72,height: 30) Hyouka.font = UIFont.systemFont(ofSize: 10) Hyouka.placeholder = "---" Hyouka.textAlignment = NSTextAlignment.center Hyouka.borderStyle = .roundedRect Hyouka.inputView = HyoukaPicker Hyouka.inputAccessoryView = ToolBar self.view.addSubview(Hyouka) } func numberOfComponents(in pickerView: UIPickerView) -> Int { return 1 }//ピッカー列数 func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { if pickerView.tag == 1 {return grouplist.count} else if pickerView.tag == 2 { return Hyoukalist.count}}//ピッカー行数=リスト数 func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { if pickerView.tag == 2{ return grouplist[row]} else if pickerView.tag == 2{ return Hyoukalist[row]} }//ピッカー最初の表示 func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { if pickerView.tag == 1{CLgroup.text = grouplist[row]} else if pickerView.tag == 2 {Hyouka.text = Hyoukalist[row]} }//ピッカーが選択されたときの挙動 @objc func onClick(){ CLgroup.endEditing(true) }//完了ボタンを押しピッカーを消す @objc func backbutton(_ sender:UIButton){ self.dismiss(animated: true, completion: nil) } @objc func changeButton(_ sender:UIButton){ let storyboard :UIStoryboard = self.storyboard! let changeview = storyboard.instantiateViewController(withIdentifier: "next")as! NextViewController changeview.clnamestring = self.CLname.text! changeview.clgroupstring = self.CLgroup.text! changeview.tanisuu = self.CLtani.text! changeview.teacherstring = self.CLteacher.text! changeview.clnumber = self.CLnumber.text! changeview.zoomId = self.CLzoomid.text! changeview.zoomPw = self.CLzoompw.text! self.present(changeview,animated: true,completion: nil) } // 改行ボタンを押した時の処理 func textFieldShouldReturn(_ CLname: UITextField) -> Bool { CLname.resignFirstResponder() return true } func textFieldshouldRetrun(_ CLtani: UITextField) -> Bool { CLtani.resignFirstResponder() return true } func textFieldshoudRetrun(_ CLteacher: UITextField) -> Bool { CLteacher.resignFirstResponder() return true } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/06/28 09:22
2020/06/28 23:45
2020/06/28 23:52
2020/06/29 08:40
2020/06/29 08:47