Просмотр исходного кода

Improve error handling in the method calling view controller.

Show an alert on failure, push or pop on success.
Ryan Olson лет назад: 12
Родитель
Сommit
ae075d9554
1 измененных файлов с 13 добавлено и 3 удалено
  1. 13 3
      Classes/Editing/FLEXMethodCallingViewController.m

+ 13 - 3
Classes/Editing/FLEXMethodCallingViewController.m

@@ -78,12 +78,22 @@
         [arguments addObject:argumentValue];
         [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];
         FLEXObjectExplorerViewController *explorerViewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:returnedObject];
         [self.navigationController pushViewController:explorerViewController animated:YES];
         [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];
     }
     }
 }
 }