2

cocos2d ゲームエンジンで使用しています。これは私のコードです:

-(void)timed1: (id)sender {
    UIAlertView *dialog = [[[UIAlertView alloc] init] retain];
    [dialog setDelegate:self];
    [dialog setTitle:@"Enter Time:"];
    [dialog setMessage:@" "];
    UITextField *nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
    [dialog addSubview:nameField];
    [nameField setBackgroundColor:[UIColor whiteColor]];
    CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 70.0);
    [dialog setTransform: moveUp];
    [dialog addButtonWithTitle:@"Done"];
    [dialog addButtonWithTitle:@"Cancel"];

    nameField.clearButtonMode = UITextFieldViewModeWhileEditing;
    nameField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

        //timeStatus is a int type global variable //   
     timeStatus =[nameField.text intValue];  //** this line not working**//  

    [nameField release];
    [dialog show];

}
4

2 に答える 2

2

値を取得できない理由は、ユーザーが何かを入力する前に関数が終了するためです! [dialog show] を呼び出すと、テキストを入力できるダイアログがユーザーに表示されます。

ユーザーがデリゲート関数をトリガーするボタンを選択するまで待ってから、テキスト フィールド プロパティにアクセスする必要があります。

これを行うには、追加した UITextField オブジェクトへのポインターを保持する (最も簡単) か、サブビューの中から再度見つけてキャストする必要があることに注意してください。

于 2009-01-03T08:37:00.787 に答える
0

後で nameField を解放し、そこから text プロパティを取得します。

于 2009-01-03T06:40:33.037 に答える