判断输入框内容,若不为空值战网跳转,若为空值则跳出提示框
这是我button用touch up inside关联的函数。跳转界面用ViewController用modal方法连接SecondViewController。但运行不成功。
@IBAction func choose(sender: AnyObject) {
if(Name.text!==""){
self.performSegueWithIdentifier("SecondViewController", sender: self)
}else{
let n=UIAlertController(title: "Sorry", message: "It is Wrong", preferredStyle: UIAlertControllerStyle.Alert)
let cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel, handler: nil)
let okAction = UIAlertAction(title: "好的", style: UIAlertActionStyle.Default, handler: nil)
n.addAction(cancelAction)
n.addAction(okAction)
self.presentViewController(n, animated: true, completion: nil)
}
}
if(Name.text!==""){ 这句是什么。。。
swift里 != 的叹号不能粘着变量,因为会误认为是optional 解包
而且!==应该是!=吧