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

后端 未结 8 1642
说谎
说谎 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:04

    based on swift:

    let alertCtr = UIAlertController(title:"Title", message:"Message", preferredStyle: .Alert)
    let Cancel = AlertAction(title:"remove", style: .Default, handler: {(UIAlertAction) -> Void in })
    let Remove = UIAlertAction(title:"remove", style: .Destructive, handler:{(UIAlertAction)-> Void 
        inself.colorLabel.hidden = true    
    })
    alertCtr.addAction(Cancel)
    alertCtr.addAction(Remove)
    
    self.presentViewController(alertCtr, animated:true, completion:nil)}
    
    0 讨论(0)
  • 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)
    
                }
    
            }
    
    0 讨论(0)
提交回复
热议问题