當文本字段被編輯時,我在NSDictionary中將textfield對象設置爲「True」。 然後for循環檢查已編輯的文本字段。使用Parse將編輯後的文本字段更新爲數據庫。我想這樣我的for-loop知道哪些文本字段應該更新我的數據庫中的哪一列。 for循環應該檢查它是否應該更新爲int或string。這可能嗎?for-loops將正確的文本字段更新到數據庫中的正確列(解析)
我的代碼:
-(IBAction)btnSaveRecipe:(id)sender{
for (NSNumber *key in allEditedTextfields) { //Loop through all keys
if ([[allEditedTextfields objectForKey:key] boolValue] == TRUE) { //See if it was edited
UITextField *tField = (UITextField *)[self.view viewWithTag:[key intValue]];
PFQuery *query = [PFQuery queryWithClassName:@"Recipe"];
[query getObjectInBackgroundWithId:detailId block:^(PFObject *recipe, NSError *error){
if (tField.tag == 110) {
recipe[@"recipeName"] = recipeName.text;
}
if (tField.tag == 111){
recipe[@"recipePrepTime"] = recipePrepTime.text;
}
if (tField.tag ==112){
recipe[@"recipeRating"] = recipeRating.text; //recipeRating is an integer
}
}];
}
}
[allEditedTextfields removeAllObjects];
}
您可以將tField.tag作爲參數傳遞,然後您的循環將準確知道要更新的內容。 – Marius 2014-08-27 09:18:39
你是什麼意思?你有一個例子嗎? – Dridia 2014-08-27 09:21:46