Sfoglia il codice sorgente

Improve error handling in the method calling view controller.

Show an alert on failure, push or pop on success.
Ryan Olson 12 anni fa
parent
commit
ae075d9554
1 ha cambiato i file con 13 aggiunte e 3 eliminazioni
  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];
     }
 }