代码之家  ›  专栏  ›  技术社区  ›  Geuis

iPhone SDK:如何获取警报中UITextField的值?

  •  1
  • Geuis  · 技术社区  · 16 年前

    我对这方面真的很陌生。我一直在努力学习一些“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];
    }
    
    1 回复  |  直到 16 年前
        1
  •  2
  •   VictorB    16 年前

    textField属性似乎未正确链接到interface builder中的UITextField对象。确保您的IBOutlet设置正确。