iPhone SDK: how to get the value of a UITextField in an alert?

情到浓时终转凉″ 提交于 2019-12-24 07:45:36

问题


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:


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.



来源:https://stackoverflow.com/questions/2204958/iphone-sdk-how-to-get-the-value-of-a-uitextfield-in-an-alert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!