Я использую cocos2d CClayer.
Я сделал Submit TextField Class, чтобы использовать имя отправки.
Я проследил за некоторым блогером и сумел показать textFiled, но shouldChangeCharactersInRange вообще не вызывал.
Как мне позвонить следует изменитьCharactersInRange? (Я не использовал 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];
}