xcode10.3でiosアプリを制作しています
https://teratail.com/questions/124301
上の記事を参考にして、pickerViewで選択しtoolbar上のDoneボタンを押す、という動作をさせたいのですが、うまくいきません
pickerViewのviを消す方法を教えて欲しいです
swift
1import UIKit 2 3class tableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource,UIPickerViewDelegate, UIPickerViewDataSource{ 4 5 var appDelegate = UIApplication.shared.delegate as! AppDelegate 6 7 //buttonを押す 8 @IBAction func switchAcounts(_ sender: Any) { 9 pickerView.frame = CGRect(x: 0, y: 0 10 , width: UIScreen.main.bounds.size.width, height: pickerView.bounds.size.height) 11 pickerView.delegate = self 12 pickerView.dataSource = self 13 14 let vi = UIView(frame: pickerView.bounds) 15 vi.backgroundColor = UIColor.white 16 vi.addSubview(pickerView) 17 18 let toolBar = UIToolbar() 19 toolBar.barStyle = UIBarStyle.default 20 toolBar.isTranslucent = true 21 toolBar.tintColor = UIColor.black 22 23 let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItem.Style.done, target: self, action: #selector(EditMoneyViewController.donePressed)) 24 let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil) 25 26 toolBar.setItems([spaceButton, doneButton], animated: false) 27 toolBar.isUserInteractionEnabled = true 28 toolBar.sizeToFit() 29 vi.addSubview(toolBar) 30 view.addSubview(vi) 31 32 let screenSize = UIScreen.main.bounds.size 33 vi.frame.origin.y = screenSize.height 34 UIView.animate(withDuration: 0.3) { 35 vi.frame.origin.y = screenSize.height - vi.bounds.size.height 36 } 37 } 38 39 func numberOfComponents(in pickerView: UIPickerView) -> Int { 40 return 1 41 } 42 43 func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 44 return appDelegate.accountSum 45 } 46 47 48 func pickerView(_ pickerView: UIPickerView, 49 titleForRow row: Int, 50 forComponent component: Int) -> String? { 51 return appDelegate.nameOfAccounts[row] 52 } 53 54 func pickerView(_ pickerView: PickerView, 55 didSelectRow row: Int, 56 inComponent component: Int) { 57 appDelegate.accountCount = row 58 } 59 60 @objc func donePressed() { 61 view.endEditing(true) 62 } 63 64 65} 66
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/31 12:00