How to add an action to a UIAlertView button using Swift iOS

后端 未结 8 1640
说谎
说谎 2020-12-12 22:13

I want to add another button other than the \"OK\" button which should just dismiss the alert. I want the other button to call a certain function.

var logInE         


        
8条回答
  •  囚心锁ツ
    2020-12-12 23:06

    See my code:

     @IBAction func foundclicked(sender: AnyObject) {
    
                if (amountTF.text.isEmpty)
                {
                    let alert = UIAlertView(title: "Oops! Empty Field", message: "Please enter the amount", delegate: nil, cancelButtonTitle: "OK")
    
                    alert.show()
                }
    
                else {
    
                var alertController = UIAlertController(title: "Confirm Bid Amount", message: "Final Bid Amount : "+amountTF.text , preferredStyle: .Alert)
                var okAction = UIAlertAction(title: "Confirm", style: UIAlertActionStyle.Default) {
                    UIAlertAction in
    
                    JHProgressHUD.sharedHUD.loaderColor = UIColor.redColor()
                            JHProgressHUD.sharedHUD.showInView(self.view, withHeader: "Amount registering" , andFooter: "Loading")
                    }
                var cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) {
                    UIAlertAction in
    
                    alertController .removeFromParentViewController()
                }
                                alertController.addAction(okAction)
                                alertController.addAction(cancelAction)
    
                    self.presentViewController(alertController, animated: true, completion: nil)
    
                }
    
            }
    

提交回复
热议问题