Permalink
Browse files

Issue #161 - adds event handlers to multiline controller

  • Loading branch information...
1 parent 126ae5c commit f61e670e5cca8452b82387797d590867b09e37e4 @escoz committed May 5, 2012
@@ -37,6 +37,8 @@ - (UITableViewCell *)getCellForTableView:(QuickDialogTableView *)tableView contr
- (void)selected:(QuickDialogTableView *)tableView controller:(QuickDialogController *)controller indexPath:(NSIndexPath *)indexPath
{
__block QMultilineTextViewController *textController = [[QMultilineTextViewController alloc] initWithTitle:self.title];
+ textController.entryElement = self;
+ textController.entryCell = [tableView cellForElement:self];
textController.resizeWhenKeyboardPresented = YES;
textController.textView.text = self.textValue;
textController.textView.autocapitalizationType = self.autocapitalizationType;
@@ -16,6 +16,8 @@
#import <UIKit/UIKit.h>
@class QMultilineTextViewController;
+@class QMultilineElement;
+@class QEntryTableViewCell;
@interface QMultilineTextViewController : UIViewController <UITextViewDelegate>
@@ -25,6 +27,10 @@
@property(nonatomic, copy) void (^willDisappearCallback)();
+@property(nonatomic, strong) QMultilineElement *entryElement;
+
+@property(nonatomic, strong) QEntryTableViewCell *entryCell;
+
- (id)initWithTitle:(NSString *)title;
@end
@@ -13,6 +13,8 @@
//
+#import "QuickDialog.h"
+
@interface QMultilineTextViewController ()
@end
@@ -26,6 +28,8 @@ @implementation QMultilineTextViewController {
@synthesize textView = _textView;
@synthesize resizeWhenKeyboardPresented = _resizeWhenKeyboardPresented;
@synthesize willDisappearCallback = _willDisappearCallback;
+@synthesize entryElement = _entryElement;
+@synthesize entryCell = _entryCell;
- (id)initWithTitle:(NSString *)title
@@ -34,6 +38,7 @@ - (id)initWithTitle:(NSString *)title
{
self.title = (title!=nil) ? title : NSLocalizedString(@"Note", @"Note");
_textView = [[UITextView alloc] init];
+ _textView.delegate = self;
_textView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_textView.font = [UIFont systemFontOfSize:18.0f];
}
@@ -106,5 +111,35 @@ - (void)setResizeWhenKeyboardPresented:(BOOL)observesKeyboard {
}
}
+- (void)textViewDidBeginEditing:(UITextView *)textView {
+ if(_entryElement && _entryElement.delegate && [_entryElement.delegate respondsToSelector:@selector(QEntryDidBeginEditingElement:andCell:)]){
+ [_entryElement.delegate QEntryDidBeginEditingElement:_entryElement andCell:self.entryCell];
+ }
+
+}
+
+- (void)textViewDidEndEditing:(UITextView *)textView {
+ _entryElement.textValue = textView.text;
+
+ if(_entryElement && _entryElement.delegate && [_entryElement.delegate respondsToSelector:@selector(QEntryDidEndEditingElement:andCell:)]){
+ [_entryElement.delegate QEntryDidEndEditingElement:_entryElement andCell:self.entryCell];
+ }
+}
+
+- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
+ if(_entryElement && _entryElement.delegate && [_entryElement.delegate respondsToSelector:@selector(QEntryShouldChangeCharactersInRangeForElement:andCell:)]){
+ return [_entryElement.delegate QEntryShouldChangeCharactersInRangeForElement:_entryElement andCell:self.entryCell];
+ }
+ return YES;
+}
+
+- (void)textViewDidChange:(UITextView *)textView {
+ _entryElement.textValue = textView.text;
+
+ if(_entryElement && _entryElement.delegate && [_entryElement.delegate respondsToSelector:@selector(QEntryEditingChangedForElement:andCell:)]){
+ [_entryElement.delegate QEntryEditingChangedForElement:_entryElement andCell:self.entryCell];
+ }
+}
+
@end

0 comments on commit f61e670

Please sign in to comment.