我在tapleviewcell中使用UIStepper,但我不知道如何在我的CoreData中保存步进值?如何将UIStepper保存到CoreData(swift 3)
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: StepperTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell") as! StepperTableViewCell
//stepper is your UIStepper reference from StepperTableViewCell
cell.stepper.tag = indexPath.row
cell.stepper.addTarget(self, action: #selector(stepperAction(sender:)), for: .valueChanged)
return cell
}
func stepperAction(sender: UIStepper) {
print("Stepper \(sender.tag) clicked. Its value \(sender.value)")
}
你想做些什么?只需保存sender.value?你真的需要核心数据吗?也许UserDefaults也会很棒?核心数据看看https://www.raywenderlich.com/145809/getting-started-core-data-tutorial或这里https://learnappdevelopment.com/ios-app-development-free/how-to -use-core-data-in-ios-10-swift-3 /或这里https://medium.com/ios-geek-community/beginners-guide-to-core-data-in-swift-3-85292ef4edd #.gnbnvyows – kuzdu
我在我的项目中使用CoreData,步进器是它的一部分。我知道如何将文本从UITextfield保存到CoreData,但我不知道如何在CoreData中保存IUStepper值 – Alex
总之我不明白这个问题。 sender.value是双精度或数字,不是吗?核心数据支持双倍。像字符串一样保存它。看到这里:http://stackoverflow.com/questions/37958530/using-double-in-core-data – kuzdu