当用户输入空字符串时如何摇动UIAlertController

时间:2015-11-16 00:08:16

标签: ios swift uialertcontroller

我是iOS新手所以请耐心等待!

我试图提示用户当他/她点击一个按钮时,一个alertController会弹出说输入你的名字来结帐,如果他们什么都不输入,AlertController应该摇动,这样他们就知道他们必须输入一个名字。我到目前为止的代码是:

@IBAction func checkoutBookButton(sender: AnyObject) {
    //Create the AlertController
    let actionSheetController: UIAlertController = UIAlertController(title: "Hey there!", message: "Please enter your name to checkout", preferredStyle: .Alert)

    //Create and add the Cancel action
    let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in
        //Do some stuff
    }


    actionSheetController.addAction(cancelAction)
    //Create and an option action


    let nextAction: UIAlertAction = UIAlertAction(title: "Checkout", style: .Default) { action -> Void in
        //Do some other stuff
    }
    actionSheetController.addAction(nextAction)

    //Add a text field
    actionSheetController.addTextFieldWithConfigurationHandler { textField -> Void in
        //TextField configuration
    }

    //Present the AlertController
    self.presentViewController(actionSheetController, animated: true, completion: nil)
}

我在另一个按钮中有一个类似的逻辑,但有一个if语句来照顾它,就像这个

if textField.submitButton = "" {
      //alert
} else {
      // do action
}

是否有类似于我可以用alertController做的事情,因为textField是在控制器中构建的而不是外部的?

非常感谢你的所有帮助!

0 个答案:

没有答案