import UIKit
class ViewController: UIViewController {
@IBOutlet weak var yearTextField: UITextField!
@IBOutlet weak var monthTextField: UITextField!
@IBOutlet weak var dayTextField: UITextField!
@IBOutlet weak var messageLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func daysButtonPressed(sender: AnyObject) {
messageLabel.text = "The button is pressed!"
var dateComponets = NSDateComponents()
dateComponets.day = 2
dateComponets.month = 10
dateComponets.year = 1999
var calendar = NSCalendar(identifier: NSGregorianCalendar)
var birthDate = calendar?.dateFromComponents(dateComponets)
var currentDate = NSDate.date()
}
}
我編譯代碼,突然它表明我這個錯誤你的年齡:date()' is unavailable: use object construction 'NSDate()'
並且也表明了我另一個錯誤多數民衆贊成是:‘?NSCalendar’「沒有名爲'dateFromComponents'的會員「,任何人都可以幫助我!我是swift新手,也是堆棧溢出如何使一個簡單的應用程序,顯示在天
應該有人更改標題,也許移動文本上面的代碼中的一段,但這個問題不應該被關閉。 – 2014-12-04 03:14:08