Present ActionSheet in SwiftUI on iPad

前端 未结 5 1703
梦谈多话
梦谈多话 2021-02-02 09:45

I\'ve gotten an ActionSheet to present just fine on an iPhone device. But it crashes for iPad. Says it needs the location for the popover. Has anyone had luck with this code? I\

5条回答
  •  难免孤独
    2021-02-02 10:27

    Here's my workaround for the bug - it maintains the "actionsheet" functionality for iPhone devices but simply creates an "alert" style controller for iPad

    It's simple enough for my case and may help others

        var preferredStyle: UIAlertController.Style
        if UIDevice.current.userInterfaceIdiom == .pad {
            preferredStyle = .alert
        }
        else{
            preferredStyle = .actionSheet
        }
        let cellMenu = UIAlertController(title: nil, message: "Bought Item?", preferredStyle: preferredStyle)
    
        //Create actions
        //Add Actions to menu
    
        self.present(cellMenu, animated: true, completion: nil)
    

提交回复
热议问题