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) –