I have subclassed UITextField so I can create some custom behaviours for it. Here are my classes:
DataboundTextField.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "TestEntities.h"
@interface DataboundTextField : UITextField <UITextFieldDelegate> {
NSString *valueMember;
NSString *displayValueMember;
ODataObject *boundEntity;
}
@property (nonatomic, retain) NSString *valueMember;
@property (nonatomic, retain) NSString *displayValueMember;
@property (nonatomic, retain) ODataObject *boundEntity;
-(void)SetupDataBinding:(ODataObject*)oDataEntity ValueMember:(NSString*)valMemberID DisplayValueMember:(NSString*)disValMember;
@end
DataboundTextField.m
#import "DataboundTextField.h"
@implementation DataboundTextField
@synthesize valueMember;
@synthesize displayValueMember;
@synthesize boundEntity;
-(id) initWithCoder:(NSCoder *)aDecoder{
if ((self = [super initWithCoder:aDecoder]))
{
self.delegate = self;
}
return self;
}
-(void)SetupDataBinding:(ODataObject*)oDataEntity ValueMember:(NSString*)valMemberID DisplayValueMember:(NSString*)disValMember{
}
-(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
return YES;
}
@end
How do I go about overriding the ValueChanged event? I cannot seem to catch it however I try. All I want to do is wack one of these subclassed Textfields on a view and catch that event and handle it.
Please help.
Thanks in advance
According to the documentation for UITextFieldDelegate, you can use
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
The text field calls this method whenever the user types a new character in the text field or deletes an existing character.
Make sure you set the delegate property of your UITextField:
- (id)init
{
if ((self = [super init]))
{
self.delegate = self;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With