Я использую cocos2d CClayer.textFiled shouldChangeCharactersInRange не работает
Я сделал Submit TextField Класс для использования submit.
Я следовал за блогером и смог показать textFiled, но shouldChangeCharactersInRange не вызывал вообще.
Как мне позвонить shouldChangeCharactersInRange? (Я не использовал xib)
в ожидании вашей помощи.
код внизу. (в Submit.h)
@property (nonatomic, retain) UITextField *mTextField;
@property (readonly) NSString *enteredText;
(в 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;
}
(в GameLayer.h)
@property (nonatomic, strong) Submit *submitForm;
(в 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];
}