textfieldのデリゲートを今はコメントアウトしていますが、外す実行時にバグります。
returnキー押したらキーボード閉じる方法を教えてください。
Swift
1import UIKit 2 3class RankingPostViewController: UIViewController, UITextFieldDelegate, UITableViewDataSource, UITableViewDelegate, UIGestureRecognizerDelegate { 4 5 @IBOutlet weak var rankingPostTableView: UITableView! 6 var rankingPostInput:UITextField! 7 8 let sectionArr = ["選択してください", "入力してください(正式名称)"] 9 let placeholderArr = ["1位の漫画", "2位の漫画", "3位の漫画"] 10 11 @IBAction func closeRankingPostVC(_ sender: Any) { 12 self.dismiss(animated: true, completion: nil) 13 } 14 15 override func viewDidLoad() { 16 super.viewDidLoad() 17 //rankingPostInput.delegate = self 18 self.rankingPostTableView.register(UINib(nibName: "RankingPostSelectCell", bundle: nil), forCellReuseIdentifier: "RankingPostSelectCell") 19 20 self.rankingPostTableView.register(UINib(nibName: "RankingPostInputCell", bundle: nil), forCellReuseIdentifier: "RankingPostInputCell") 21 22 // 空のセルの境界線を消す 23 rankingPostTableView.tableFooterView = UIView() 24 } 25 26 override func didReceiveMemoryWarning() { 27 super.didReceiveMemoryWarning() 28 } 29 30 func textFieldShouldReturn(_ textField: UITextField) -> Bool{ 31 32 // キーボードを閉じる 33 rankingPostInput.resignFirstResponder() 34 35 return true 36 } 37 38 39 // セクションの数 40 func numberOfSections(in tableView: UITableView) -> Int { 41 return sectionArr.count 42 } 43 44 // セクションのタイトル 45 func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 46 return sectionArr[section] 47 } 48 49 // tableViewのセルの数を返す 50 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 51 if section == 0 { 52 return 1 53 } 54 else if section == 1 { 55 return 3 56 } 57 else { 58 return 0 59 } 60 } 61 62 // tableViewのセルを返す 63 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 64 65 if indexPath.section == 0 { 66 let rankingPostSelectCell = tableView.dequeueReusableCell(withIdentifier: "RankingPostSelectCell", for: indexPath as IndexPath) as! RankingPostSelectCell 67 68 return rankingPostSelectCell 69 } 70 else if indexPath.section == 1 { 71 let rankingPostInputCell = tableView.dequeueReusableCell(withIdentifier: "RankingPostInputCell", for: indexPath as IndexPath) as! RankingPostInputCell 72 73 rankingPostInput = rankingPostInputCell.contentView.viewWithTag(1) as! UITextField 74 rankingPostInput.placeholder = placeholderArr[indexPath.row] 75 76 return rankingPostInputCell 77 } 78 else { 79 let rankingPostInputCell = tableView.dequeueReusableCell(withIdentifier: "RankingPostInputCell", for: indexPath as IndexPath) as! RankingPostInputCell 80 81 return rankingPostInputCell 82 } 83 } 84 85 // Cell が選択された場合 86 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 87 performSegue(withIdentifier: "toRankingPostCategoryViewController",sender: nil) 88 } 89 90} 91
どうバグるのでしょうか?