2012-02-10 1 views
1

저는 cocos2d CClayer를 사용하고 있습니다.textFiled shouldChangeCharactersInRange 함수가 작동하지 않았습니다.

전송 이름을 사용하도록 제출 TextField 클래스를 만들었습니다.

일부 블로거를 따라 갔다가 textFiled를 표시했지만 shouldChangeCharactersInRange가 전혀 호출하지 않았습니다.

shouldChangeCharactersInRange를 어떻게 호출합니까? (나는 xib를 사용하지 않았다)

당신의 도움을 기다리고있다.

코드입니다. (Submit.h)에 (Submit.m)에

@property (nonatomic, retain) UITextField *mTextField; 
@property (readonly) NSString *enteredText; 

(GameLayer.h)에
-(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; 
} 

-(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]; 
} 
(GameLayer.m)에

@property (nonatomic, strong) Submit *submitForm; 

답변

1

UITextField Delega 테 방법

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange: (NSRange)range replacementString:(NSString *)string 

,

당신의 UITextField의 위임 속성을 설정해야합니다.

으로,

theTextField.delegate = self;