如何检查文本字段中是否有文本并单击按钮

时间:2013-03-22 09:11:13

标签: iphone objective-c ipad uitextfield

我有应用程序我希望如果textfield中没有任何数据并且还没有点击按钮,那么它会显示警报视图。否则,它会调用一个方法。我有BOOL isClicked,单击按钮时我已设置为YES,但如何检查此textfield

BOOL isClicked;
feedbackTextfield; 
if(isClicked && feedbackTexfield)

2 个答案:

答案 0 :(得分:2)

试试这个代码......

  if((!isCliked) && ([feedbackTexfield.text length] == 0))
    {
        //button may not clicked or feedbackTextfield not contains text block.

        //Display your alert stuff

         UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Button is not clicked" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
              [alertView show];  
    }
    else
    {
        //button may clicked or feedbackTextfield contains text block.
    }

这可以解决你的问题...

答案 1 :(得分:0)

if(yourTextField.text.length == 0 && isClicked == FALSE)
{
   // Here goes Alert
}
else
{
  // Write your stuff
}