Преглед на файлове

Improve error handling in the method calling view controller.

Show an alert on failure, push or pop on success.
Ryan Olson преди 12 години
родител
ревизия
ae075d9554
променени са 1 файла, в които са добавени 13 реда и са изтрити 3 реда
  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];
     }
 }