0
我正在做一個減肥應用程序,可以節省你每天的體重。我需要知道如何保存當前日期的重量,然後使文本字段在第二天爲空。我使用NSUserDefault保存了文本字段。我試圖做其他的健身應用程序有那裏的用戶界面,你可以去看看前幾天,看看保存的數據。有人能指引我走向正確的方向嗎?謝謝!我將如何保存特定日期的文本字段?
override func didMoveToView(view: SKView) {
let stringKey = NSUserDefaults.standardUserDefaults()
textFieldWeight.text = stringKey.stringForKey("saveWeight")
addTextFieldForWeight()
}
func addTextFieldForWeight() {
textFieldWeight.borderStyle = UITextBorderStyle.Line
textFieldWeight.textColor = UIColor.whiteColor()
textFieldWeight.autocorrectionType = UITextAutocorrectionType.Yes
textFieldWeight.keyboardType = UIKeyboardType.NumberPad
textFieldWeight.delegate = self
textFieldWeight.backgroundColor = UIColor.clearColor()
textFieldWeight.returnKeyType = UIReturnKeyType.Done
textFieldWeight.contentVerticalAlignment = UIControlContentVerticalAlignment.Center
self.view?.addSubview(textFieldWeight)
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
if node.name == "next" {
let nextDay = NSCalendar.currentCalendar().dateByAddingUnit(NSCalendarUnit.CalendarUnitDay,value: 1,toDate:
NSDate(),options: nil)
let formatter = NSDateFormatter()
formatter.dateStyle = NSDateFormatterStyle.FullStyle
let dateString = formatter.stringFromDate(nextDay!)
dateLabel.text = String(dateString)
}
if node.name == "before" {
let earlyDate = NSCalendar.currentCalendar().dateByAddingUnit(NSCalendarUnit.CalendarUnitDay,value: -1,toDate:
NSDate(),options: NSCalendarOptions.WrapComponents)
let formatter = NSDateFormatter()
formatter.dateStyle = NSDateFormatterStyle.FullStyle
let dateString = formatter.stringFromDate(earlyDate!)
dateLabel.text = String(dateString)
}
}
你需要保存每天病史?我的意思是每一天的體重。 –
是的,我可能會改變它的卡路里,而不是體重,但我想保存每一天。 – coding22
對於必須使用[源碼](http://www.appcoda.com/sqlite-database-ios-app-tutorial/)或[核心數據](https://developer.apple.com/library/ios /documentation/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html) –