textField1の文字列を時刻情報に変換して、その時刻にアラートを出したいと考えております。
下記のコードで動かしてみたところ、
textField1は11:11
date1は2000-01-01 02:11:00 +0000
となり、その時刻になってもアラートは出ませんでした。date1を日本時間に変換できればアラートを出せると思うのですが、なにが間違っているか教えてほしいです。
swift
1//ViewControllerクラス 2 textField1.text = "11:11" 3 let dateFormatter = NSDateFormatter() 4 dateFormatter.dateFormat = "HH:mm"; 5 dateFormatter.locale = NSLocale(localeIdentifier: "ja_JP") 6 println(textField1.text) 7 var date1 = dateFormatter.dateFromString(textField1.text)!; 8 println(date1) 9 10 var notification:UILocalNotification = UILocalNotification() 11 notification.fireDate = date1 12 13//AppDelegateクラス 14 func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) { 15 let alertController = UIAlertController(title:"テスト",message:"", preferredStyle:.Alert) 16 let action1 = UIAlertAction(title: "Yes", style: .Default) 17 alertController.addAction(action1) 18 let action2 = UIAlertAction(title: "No", style: .Cancel,handler:nil) 19 alertController.addAction(action2) 20 self.window?.rootViewController?.presentViewController(alertController, animated: true, completion: nil) 21 } 22 23
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/11/09 03:13