Przeglądaj źródła

Show an alert when property setting fails.

Also auto-pop when the setting succeeds (except for with switches).
Ryan Olson 12 lat temu
rodzic
commit
02fbeaabc6
1 zmienionych plików z 15 dodań i 3 usunięć
  1. 15 3
      Classes/Editing/FLEXPropertyEditorViewController.m

+ 15 - 3
Classes/Editing/FLEXPropertyEditorViewController.m

@@ -60,9 +60,21 @@
     id userInputObject = self.firstInputView.inputValue;
     NSArray *arguments = userInputObject ? @[userInputObject] : nil;
     SEL setterSelector = [FLEXRuntimeUtility setterSelectorForProperty:self.property];
-    [FLEXRuntimeUtility performSelector:setterSelector onObject:self.target withArguments:arguments error:NULL];
-    
-    self.firstInputView.inputValue = [FLEXRuntimeUtility valueForProperty:self.property onObject:self.target];
+    NSError *error = nil;
+    [FLEXRuntimeUtility performSelector:setterSelector onObject:self.target withArguments:arguments error:&error];
+    if (error) {
+        NSString *title = @"Property Setter Failed";
+        NSString *message = [error localizedDescription];
+        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
+        [alert show];
+        self.firstInputView.inputValue = [FLEXRuntimeUtility valueForProperty:self.property onObject:self.target];
+    } else {
+        // If the setter was called without error, pop the view controller to indicate that and make the user's life easier.
+        // Don't do this for simulated taps on the action button (i.e. from switch/BOOL editors). The experience is weird there.
+        if (sender) {
+            [self.navigationController popViewControllerAnimated:YES];
+        }
+    }
 }
 
 - (void)argumentInputViewValueDidChange:(FLEXArgumentInputView *)argumentInputView