1

cocos2d CClayer を使用しています。

送信名を使用するために Submit TextField Class を作成しました。

私はいくつかのブロガーをフォローし、なんとか 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];   
}
4

1 に答える 1