How do I get the value of a textbox as an alert using Cocos2d?

I am trying to develop an application using Cocos2d. I cannot get the value from the textbox. How do I get the value of a textbox (as an alert) using 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 setBackgroundColor:[UIColor clearColor]];
    [dialog addButtonWithTitle:@"Done"];
    [dialog show];

    nameField.clearButtonMode = UITextFieldViewModeWhileEditing;
    nameField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    nameField.keyboardAppearance = UIKeyboardAppearanceAlert;
    nameField.autocapitalizationType = UITextAutocapitalizationTypeWords;

        //  timeStatus is a int type global variable
    timeStatus =[nameField.text intValue]; // this line not working i can't getting value namefield


    [dialog release];
    [nameField release];

}

      

0


source to share


1 answer


Action sheets and alerts are processed asynchronously. In your case, the [dialog show] message is simply scheduling a show event for later execution (handled by the main run loop). If you add some NSLog (), you will see that the [show] message is returned almost immediately, after which your user has not entered any data, the nameField text is empty, and this is converted to int from 0.



You want the blocking dialog box modal with I / O sheets and warnings not to be intended for user input outside of clicking yes / no / cancel buttons. You will have to prepare your own view: not too difficult, but it takes more work than using an action / warning sheet.

0


source







All Articles