我喜欢在编辑完 totalAmount 后立即更新 textfield2,我正在尝试以下操作:
totalAmount.addTarget(self, action: "changeTextField2:", forControlEvents: UIControlEvents.EditingDidEndOnExit)
func changeTextField2(textField: UITextField) {
print("Total amount: \(totalAmount.text)")
//amount vat - calculate vat based on textField
amountVAT.text = "88"
}
我正在保存文本字段值
func newItem(){
let context = self.context
let ent = NSEntityDescription.entityForName("List", inManagedObjectContext: context)
let nItem = List(entity: ent!, insertIntoManagedObjectContext: context)
let numberFormatter = NSNumberFormatter()
nItem.amountVAT = numberFormatter.numberFromString(amountVAT.text!)
.....more values
nItem.invoiceImage = UIImagePNGRepresentation(imageHolder.image!)
do {
try context.save()
} catch {
print(error)
}
}
func saveValues(sender: AnyObject) {
if nItem != nil {
editItem()
} else {
newItem()
}
dismissVC()
}