views:

245

answers:

1

I'm really new at this. I've been working my way through a couple of "HelloWorld" type tutorials that basically have a text field, a button, and when you click the button it alerts whatever's in the text field. I've gotten as far as getting an alert to show and being able to set the title, message, and button text directly. However my attempts at getting the contents of my UITextField keep failing. I either get errors, no response, or just "(null)". My code's here.

@synthesize textField;


- (IBAction)btnClicked:(id)sender {

    //text of textField
    NSString *str = [[NSString alloc] initWithFormat:@"Hello, %@", textField.text];

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello!" 
                    message:str delegate:self 
                    cancelButtonTitle:@"Done" 
                    otherButtonTitles:nil];


    [alert show];
    [alert autorelease];
}
+1  A: 

It looks like the textField property is not properly linked to the UITextField object you have in interface builder. Make sure your IBOutlets are set correctly.

Victorb