【问题标题】:How to check whether there is text in text field and button is clicked如何检查文本字段中是否有文本并单击按钮
【发布时间】:2013-03-22 09:11:13
【问题描述】:

我有我想要的应用程序,如果textfield 中没有任何数据并且尚未单击按钮,则它会显示警报视图。否则,它调用一个方法。我有BOOL isClicked,当点击按钮时我已经设置为YES,但是如何检查这个和textfield

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

【问题讨论】:

  • if(yourTextField.text.length == 0) 用于检查文本是否存在
  • 你的真正目的是什么?
  • 我希望当文本为零且 BOOL 为假时显示警报

标签: iphone objective-c ipad uitextfield


【解决方案1】:

试试这个代码....

  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.
    }

这是解决你的问题...

【讨论】:

  • 它只在文本条件下工作正常 BOOL 为假仍然没有显示警报
  • 你能帮帮我吗
  • 插入 && 我们将使用 ||那么它会正常工作请编辑它我接受你的回答
  • "如果文本字段中没有任何数据并且未单击按钮,则显示警报"这是您发布的要求,根据我已经制定了条件。
【解决方案2】:
if(yourTextField.text.length == 0 && isClicked == FALSE)
{
   // Here goes Alert
}
else
{
  // Write your stuff
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-23
    • 1970-01-01
    • 2022-01-03
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多