Tuesday, March 30, 2010

Another SuperDB Validation Tweak

In ManagedObjectAttributeEditor.m, there is this method:

...
#pragma mark -
#pragma mark Alert View Delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == [alertView cancelButtonIndex]) {
[self.managedObject.managedObjectContext rollback];
[self.navigationController popViewControllerAnimated:YES];
}

}

@end

Now, if you say you're going to fix, and then don't, the context never gets rolled back. It should really be:
...
#pragma mark -
#pragma mark Alert View Delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
[self.managedObject.managedObjectContext rollback];
if (buttonIndex == [alertView cancelButtonIndex]) {
[self.navigationController popViewControllerAnimated:YES];
}

}

@end

Since we don't have bindings, the incorrect value shown in the GUI will stay there, we're just removing it from the context. When they hit Save again, we'll copy the value back into the context, but if they hit cancel, we won't leave an invalid value sitting in the unsaved context.

No comments:

Post a Comment