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

Add delegate protocol to inform users of FLEXArgumentInputViews when the value changes.

Ryan Olson лет назад: 12
Родитель
Сommit
2fa672906d

+ 10 - 1
Classes/Editing/Argument Input Views/FLEXArgumentInputTextView.m

@@ -9,7 +9,7 @@
 #import "FLEXArgumentInputTextView.h"
 #import "FLEXUtility.h"
 
-@interface FLEXArgumentInputTextView ()
+@interface FLEXArgumentInputTextView () <UITextViewDelegate>
 
 @property (nonatomic, strong) UITextView *inputTextView;
 @property (nonatomic, readonly) NSUInteger numberOfInputLines;
@@ -29,12 +29,21 @@
         self.inputTextView.layer.borderWidth = 1.0;
         self.inputTextView.autocapitalizationType = UITextAutocapitalizationTypeNone;
         self.inputTextView.autocorrectionType = UITextAutocorrectionTypeNo;
+        self.inputTextView.delegate = self;
         [self addSubview:self.inputTextView];
     }
     return self;
 }
 
 
+#pragma mark - Text View Changes
+
+- (void)textViewDidChange:(UITextView *)textView
+{
+    [self.delegate argumentInputViewValueDidChange:self];
+}
+
+
 #pragma mark - Layout and Sizing
 
 - (void)layoutSubviews

+ 11 - 0
Classes/Editing/Argument Input Views/FLEXArgumentInputView.h

@@ -13,6 +13,8 @@ typedef NS_ENUM(NSUInteger, FLEXArgumentInputViewSize) {
     FLEXArgumentInputViewSizeLarge
 };
 
+@protocol FLEXArgumentInputViewDelegate;
+
 @interface FLEXArgumentInputView : UIView
 
 - (instancetype)initWithArgumentTypeEncoding:(const char *)typeEncoding;
@@ -30,6 +32,9 @@ typedef NS_ENUM(NSUInteger, FLEXArgumentInputViewSize) {
 /// Useful to increase the use of space if there is only one input view on screen (i.e. for property and ivar editing).
 @property (nonatomic, assign) FLEXArgumentInputViewSize targetSize;
 
+/// Users of the input view can get delegate callbacks for incremental changes in user input.
+@property (nonatomic, weak) id <FLEXArgumentInputViewDelegate> delegate;
+
 // Subclasses can override
 
 /// If the input view has one or more text views, returns YES when one of them is focused.
@@ -47,3 +52,9 @@ typedef NS_ENUM(NSUInteger, FLEXArgumentInputViewSize) {
 + (CGFloat)titleBottomPadding;
 
 @end
+
+@protocol FLEXArgumentInputViewDelegate <NSObject>
+
+- (void)argumentInputViewValueDidChange:(FLEXArgumentInputView *)argumentInputView;
+
+@end