UIActionSheet with swift

后端 未结 5 1336
清酒与你
清酒与你 2021-02-20 15:07

I created an action sheet, but the problem is that the delegate method is not called

 myActionSheet = UIActionSheet()
        myActionSheet.addButtonWithTitle(\"         


        
5条回答
  •  隐瞒了意图╮
    2021-02-20 15:31

    Updated for Swift 3 :

    If you want to show/open UIActionSheet on Button click, used below simple and updated code in yourViewController:

    //Method Defination :

    func showPaymentModeActionSheet()  {
    
        // 1
        let optionMenu = UIAlertController(title: nil, message: "Choose Payment Mode", preferredStyle: .actionSheet)
    
        // 2
        let fullAction = UIAlertAction(title: "FULL", style: .default, handler: {
            (alert: UIAlertAction!) -> Void in
            self.mPaymentModeTextField.text = "FULL"
    
        })
        let addvanceAction = UIAlertAction(title: "ADVANCE", style: .default, handler: {
            (alert: UIAlertAction!) -> Void in
            self.mPaymentModeTextField.text = "ADVANCE"
        })
    
        //
        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: {
            (alert: UIAlertAction!) -> Void in
        })
    
    
        // 4
        optionMenu.addAction(fullAction)
        optionMenu.addAction(addvanceAction)
        optionMenu.addAction(cancelAction)
    
        // 5
        self.present(optionMenu, animated: true, completion: nil)
    }
    

    //Method Call :

    @IBAction func actionOnPaymentModeButton(_ sender: Any) {
        // open action sheet
        showPaymentModeActionSheet()
    }
    

提交回复
热议问题