Explorar el Código

Improve error handling in the method calling view controller.

Show an alert on failure, push or pop on success.
Ryan Olson hace 12 años
padre
commit
ae075d9554
Se han modificado 1 ficheros con 13 adiciones y 3 borrados
  1. 13 3
      Classes/Editing/FLEXMethodCallingViewController.m

+ 13 - 3
Classes/Editing/FLEXMethodCallingViewController.m

@@ -78,12 +78,22 @@
         [arguments addObject:argumentValue];
     }
     
-    id returnedObject = [FLEXRuntimeUtility performSelector:method_getName(self.method) onObject:self.target withArguments:arguments error:NULL];
+    NSError *error = nil;
+    id returnedObject = [FLEXRuntimeUtility performSelector:method_getName(self.method) onObject:self.target withArguments:arguments error:&error];
     
-    // For non-nil (or void) return types, push an explorer view controller to display the returned object
-    if (returnedObject) {
+    if (error) {
+        NSString *title = @"Method Call Failed";
+        NSString *message = [error localizedDescription];
+        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
+        [alert show];
+    } else if (returnedObject) {
+        // For non-nil (or void) return types, push an explorer view controller to display the returned object
         FLEXObjectExplorerViewController *explorerViewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:returnedObject];
         [self.navigationController pushViewController:explorerViewController animated:YES];
+    } else {
+        // If we didn't get a returned object but the method call succeeded,
+        // pop this view controller off the stack to indicate that the call went through.
+        [self.navigationController popViewControllerAnimated:YES];
     }
 }