大家好
小弟最近在家看书自学Swift
在练习操作datepicker元件时
想让显示的讯息 随着选取时间而更动内容
却完全没有动静 只显示起始时间
想请问下面程式码有哪里是有问题的吗?
import UIKit
class ViewController: UIViewController {
var dateFormatter = NSDateFormatter()
@IBOutlet var datePicker: UIDatePicker!
@IBOutlet var labelMsg: UILabel!
@IBAction func dateChange(sender: UIDatePicker) {
labelMsg.text = dateFormatter.stringFromDate(datePicker.date)
}
override func viewDidLoad() {
super.viewDidLoad()
datePicker.datePickerMode = UIDatePickerMode.DateAndTime
datePicker.locale = NSLocale(localeIdentifier: "zh_TW")
datePicker.date = NSDate()
dateFormatter.dateFormat = "西元y年MM月dd日hh时mm分ss秒"
labelMsg.text = dateFormatter.stringFromDate(datePicker.date)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
感谢大家!!!