いつもお世話になっております。
前提・実現したいこと
ユーザーに時間を設定させて、設定した時間をTableViewCellのラベルに表示させたいです。
UITableViewのセルをタップするとUIDatePickerが画面下部に表示され(ソフトウェアキーボードみたいなイメージ)
設定完了のボタンを押すとUIDatePickerが閉じて設定した時間がタップしたUITableViewCellの
ラベルに表示するような実装を行いたいのですが、方法がわかりませんでした。
どなたかご教示頂けると幸いです。
追記
イメージの画像を追加しました
試したこと
全くわからなかったので取り敢えず下記を試してみましたが
取り敢えず画面上部にPickerは出ましたが完了のボタンを設置する必要もあれば
そのボタンを押したら閉じる必要もありますが方法が全くわかりませんでした。
Swift
1class AlarmViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { 2 @IBOutlet weak var tableView: UITableView! 3 4 var cellItems = [ ["前日", "当日"]] 5 6 override func viewDidLoad() { 7 super.viewDidLoad() 8 9 tableView.delegate = self 10 tableView.dataSource = self 11 12 if let path: String = Bundle.main.path(forResource: "test", ofType: "json") { 13 let fileHandle : FileHandle = FileHandle(forReadingAtPath: path)! 14 let data : Data = fileHandle.readDataToEndOfFile() 15 16 do { 17 let json = try JSON(data: data) 18 let town = json["Town"][0] 19 let trashInfo = town["TrashInfo"] 20 21 var trashKindArray = [String]() 22 for (_,subJson):(String, JSON) in trashInfo { 23 for (key,_):(String, JSON) in subJson { 24 trashKindArray.append(key) 25 } 26 } 27 cellItems.append(trashKindArray) 28 } catch { 29 print("ファイルの内容取得時に失敗") 30 } 31 }else { 32 print("指定されたファイルが見つかりません") 33 } 34 } 35 36 override func didReceiveMemoryWarning() { 37 super.didReceiveMemoryWarning() 38 } 39 40 func numberOfSections(in tableView: UITableView) -> Int { 41 return cellItems.count 42 } 43 44 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 45 return cellItems[section].count 46 } 47 48 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 49 switch indexPath.section{ 50 case 0: 51 let cell = tableView.dequeueReusableCell(withIdentifier: "AlarmTimeCell", for: indexPath) as! AlarmTableViewCell 52 cell.textLabel?.text = cellItems[indexPath.section][indexPath.row] 53 cell.timeLabel.text = "ここに時間を入れたい" 54 55 return cell 56 case 1: 57 let cell = tableView.dequeueReusableCell(withIdentifier: "AlarmSwitchCell", for: indexPath) 58 cell.textLabel?.text = cellItems[indexPath.section][indexPath.row] 59 60 if cell.accessoryView == nil { 61 cell.accessoryView = UISwitch() 62 } 63 64 return cell 65 default: 66 return tableView.dequeueReusableCell(withIdentifier: "AlarmTimeCell", for: indexPath) 67 } 68 } 69 70 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 71 tableView.deselectRow(at: indexPath, animated: true) 72 } 73}
class AlarmTableViewCell: UITableViewCell { @IBOutlet weak var timeLabel: UILabel! override func awakeFromNib() { super.awakeFromNib() } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) } }
イメージ画像
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/09 05:46
2018/08/09 05:56
2018/08/09 06:10
2018/08/09 07:10
2018/08/09 07:49
2018/08/10 01:35
2018/08/10 13:59
2018/08/11 06:07