1

我真的很陌生。我一直在学习几个“HelloWorld”类型的教程,这些教程基本上有一个文本字段、一个按钮,当您单击该按钮时,它会提醒文本字段中的任何内容。我已经获得了要显示的警报并能够直接设置标题、消息和按钮文本。但是,我尝试获取 UITextField 内容的尝试一直失败。我要么得到错误,没有响应,要么只是“(null)”。我的代码在这里。

@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];
}
4

1 回答 1

2

看起来 textField 属性未正确链接到您在界面生成器中拥有的 UITextField 对象。确保您的 IBOutlets 设置正确。

于 2010-02-05T04:15:56.423 回答