How to update data to Mobile Services - iOS / iPhone (Windows Azure)
How to update data to Mobile Services - iOS / iPhone (Windows Azure) สรุปวิธีการบันทึก Update แก้ไขข้อมูลบน Table ของ Mobile Services บน Windows Azure ด้วย iOS / iPhone แบบสั้น ๆ ง่าย ๆ
-(void)updateItem:(NSMutableDictionary *)mutable completion:(QSCompletionBlock)completion
{
// Update the item in the TodoItem table and remove from the items array on completion
[self.table update:mutable completion:^(NSDictionary *item, NSError *error) {
[self logErrorIfNotNil:error];
// Let the caller know that we have finished
completion();
}];
}
- (IBAction)btnSave:(id)sender {
// Find item that was commited for editing (update)
NSDictionary *item = [self.memberService.items objectAtIndex:0];
NSMutableArray *mutableItems = (NSMutableArray *) upItems;
// Set the item to be complete (we need a mutable copy)
NSMutableDictionary *mutable = [item mutableCopy];
[mutable setObject:txtUsername.text forKey:@"username"];
[mutable setObject:txtPassword.text forKey:@"password"];
[mutable setObject:txtName.text forKey:@"name"];
[mutable setObject:txtEmail.text forKey:@"email"];
[mutable setObject:txtTel.text forKey:@"tel"];
// Replace the original in the items array
NSUInteger index = [upItems indexOfObjectIdenticalTo:item];
[mutableItems replaceObjectAtIndex:index withObject:mutable];
// Ask the todoService to set the item's complete value to YES, and remove the row if successful
[self.memberService updateItem:mutable completion:^(NSUInteger index)
{
UIAlertView *av =
[[UIAlertView alloc]
initWithTitle:@"Update Data"
message:@"Update Data Successfully."
delegate: self
cancelButtonTitle:@"OK"
otherButtonTitles:nil
];
[av show];
//ViewController *view2 = [[[ViewController alloc] initWithNibName:nil bundle:nil] autorelease];
//[self presentViewController:view2 animated:YES completion:NULL];
}];
}
Example
Show Case 3 : Update Data (iOS / iPhone and Mobile Services)