如何控制两个UITextFields'数据同时?

时间:2015-10-03 21:08:42

标签: swift

我有两个UIButton和一个isEmpty。此按钮获取填充字段的值。如果两个字段都填充了函数错误我使用了UITextField方法和if语句,但它仍然没有控制if ICAOCodeField.text?.isEmpty == true && airportNameField.text?.isEmpty == true { let alert1 = UIAlertController(title: "Neither fields cannot be filled", message: "Use only one field", preferredStyle: .Alert) alert1.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil)) presentViewController(alert1, animated: true, completion: nil) return } else if ICAOCodeField.text?.isEmpty == false && airportNameField.text?.isEmpty == false { let alert2 = UIAlertController(title: "Neither field cannot be empty", message: "Enter Value", preferredStyle: .Alert) alert2.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil)) presentViewController(alert2, animated: true, completion: nil) return } else if ICAOCodeField.text?.isEmpty == true && airportNameField.text?.isEmpty == false { primitiveTowersArray = getTowerNames(ICAOCode: getICAOFromAirportName(airportNameField.text!)) } else if ICAOCodeField.text?.isEmpty == false && airportNameField.text?.isEmpty == true{ primitiveTowersArray = getTowerNames(ICAOCode: ICAOCodeField.text!) } s。

P.S。:我已经填满了这些字段,它警告......不能为空。

arrayfun

1 个答案:

答案 0 :(得分:0)

试试这个,

Swift 1.2

if(Your_textfiled1.text == "" && Your_textfiled2.text == "")
{
  let alert1 = UIAlertController(title: "Neither fields cannot be filled", message: "Use only one field", preferredStyle: .Alert)
            alert1.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
            presentViewController(alert1, animated: true, completion: nil)
}
else
{
 // Do something
}

Swift 2.0

 if(Your_textfiled1.text! == "" && Your_textfiled2.text! == "")
    {
      let alert1 = UIAlertController(title: "Neither fields cannot be filled", message: "Use only one field", preferredStyle: .Alert)
                alert1.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
                presentViewController(alert1, animated: true, completion: nil)
    }
    else
    {
     // Do something
    }