ActionSheet not working iPad

后端 未结 8 2079
粉色の甜心
粉色の甜心 2020-12-02 16:25

I\'m using ActionSheet in my application. On my iPhone it works, but it doesn\'t on the iPad simulator.

this is my code:

@IBAction func dialog(send         


        
8条回答
  •  时光取名叫无心
    2020-12-02 16:46

    Swift 3

    As said before, you should configure UIAlertController to be presented on a specific point on iPAD.

    Example for navigation bar:

        // 1
        let optionMenu = UIAlertController(title: nil, message: "Choose an option", preferredStyle: .actionSheet)
    
        // 2
        let deleteAction = UIAlertAction(title: "Option 1", style: .default, handler: {
            (alert: UIAlertAction!) -> Void in
            print("option 1 pressed")
        })
        let saveAction = UIAlertAction(title: "Option 2", style: .default, handler: {
            (alert: UIAlertAction!) -> Void in
            print("option 2 pressed")
        })
    
        //
        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: {
            (alert: UIAlertAction!) -> Void in
            print("Cancelled")
        })
    
    
        // 4
    
        optionMenu.addAction(deleteAction)
        optionMenu.addAction(saveAction)
        optionMenu.addAction(cancelAction)
    
        // 5
    
        optionMenu.popoverPresentationController?.barButtonItem = self.navigationItem.rightBarButtonItem
    
        self.present(optionMenu, animated: true) { 
            print("option menu presented")
        }
    

提交回复
热议问题