Swift3.0/Xcode8.を使用しています。
viewの中にはLabelとButtonを配置しています。
buttonを押すとアラートを表示させ、アラートの中にはdatepickerが配置されています。
datepickerを操作してokボタンを押した時にviewのラベルにその時間を反映させた文字列を表示させたいのですが、okボタンを押した途端にアプリが落ちてしまいます。
解決の目処が立ちませんので、ご指導の程、よろしくお願いいたします。
Samplecode
@IBAction func upTimeButton(_ sender: Any) {
let title = "起床時間を設定"
let message = "\n\n\n\n\n\n\n\n"
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler:{
(action: UIAlertAction!) -> Void in
//初期設定で表示される日時の形式 self.Todays.dateFormat = "yyyy/MM/dd hh:mm" //取り出すピッカーに表示されている文字列 let SetPickerData = self.Todays.string(from:(sender as AnyObject).date ) self.upTimeLabel.text = SetPickerData }) let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { action in } alert.view.addSubview(datePicker) alert.addAction(okAction) alert.addAction(cancelAction) present(alert, animated: true, completion: nil) }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/11 00:23