I'm using cocos2d CClayer.
I made Submit TextField Class to use submit name.
I followed some blogger and managed to show textFiled, but the shouldChangeCharactersInRange didn't call at all.
How do i call shouldChangeCharactersInRange? (I didn't use xib)
waiting for your help.
code bellow. (in Submit.h)
@property (nonatomic, retain) UITextField *mTextField;
@property (readonly) NSString *enteredText;
(in Submit.m)
-(id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle okButtonTitle:(NSString *)okButtonTitle{
if(self = [super initWithTitle:title message:message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)okButtonTitle, nil]) {
UITextField *theTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 65.0, 260.0, 25.0)];
[theTextField setBackgroundColor:[UIColor whiteColor]];
[self addSubview:theTextField];
self.mTextField = theTextField;
[theTextField release];
}
return self;
}
- (BOOL)textField: (UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSUInteger newLength = [textField.text length] + [string length] - range.length;
return (newLength > MAXLENGTH) ? NO : YES;
}
(in GameLayer.h)
@property (nonatomic, strong) Submit *submitForm;
(in GameLayer.m)
-(void) submit:(id) sender {
Submit *prompt = [Submit alloc];
prompt = [prompt initWithTitle:@"Post Score" message:@"Enter Your Name\n\n\n" delegate:self cancelButtonTitle:@"Cancel" okButtonTitle:@"Okay"];
CGAffineTransform moveDown = CGAffineTransformMakeTranslation(0,-10);
[prompt setTransform:moveDown];
self.submitForm = prompt;
[submitForm show];
[prompt release];
}