How to use UIAlertController to replace UIActionSheet?

前端 未结 6 1393
醉话见心
醉话见心 2020-12-13 23:29

I am maintaining an old iOS project which based on SDK 6.0.

A method on this project called

-(void) showComboBox:(UIView*)view:withOptions:(NSDictiona

6条回答
  •  清歌不尽
    2020-12-14 00:05

    Swift update -

        let actionSheet = UIAlertController.init(title: "Please choose a source type", message: nil, preferredStyle: .actionSheet)
        actionSheet.addAction(UIAlertAction.init(title: "Take Photo", style: UIAlertActionStyle.default, handler: { (action) in
            self.openCamera()
        }))
        actionSheet.addAction(UIAlertAction.init(title: "Choose Photo", style: UIAlertActionStyle.default, handler: { (action) in
            self.showPhotoLibrary()
        }))
        actionSheet.addAction(UIAlertAction.init(title: "Cancel", style: UIAlertActionStyle.cancel, handler: { (action) in
            // self.dismissViewControllerAnimated(true, completion: nil) is not needed, this is handled automatically,
             //Plus whatever method you define here, gets called,
            //If you tap outside the UIAlertController action buttons area, then also this handler gets called.
        }))
        //Present the controller
        self.present(actionSheet, animated: true, completion: nil)
    

提交回复
热议问题