Ios 当我点击UIImagePicker galary的图像按钮在iPad上选择图像时,应用程序崩溃了,为什么?

Ios 当我点击UIImagePicker galary的图像按钮在iPad上选择图像时,应用程序崩溃了,为什么?,ios,swift,ipad,uiimagepickercontroller,Ios,Swift,Ipad,Uiimagepickercontroller,我使用UIImagePicker拾取图像,iPhone gallery可以很好地拾取图像。但当我在xcode中在iPad上测试应用程序时,当我点击图像按钮时,应用程序崩溃了,我不知道为什么 代码如下: @IBAction func addProfileBtnAction(_ sender: Any) { let actionSheetController: UIAlertController = UIAlertController(title: nil, message: nil, p

我使用UIImagePicker拾取图像,iPhone gallery可以很好地拾取图像。但当我在xcode中在iPad上测试应用程序时,当我点击图像按钮时,应用程序崩溃了,我不知道为什么

代码如下:

 @IBAction func addProfileBtnAction(_ sender: Any) {

   let actionSheetController: UIAlertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

   //Create and add the Cancel action
   let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel) { action -> Void in
       //Just dismiss the action sheet
   }
   actionSheetController.addAction(cancelAction)
   //Create and add first option action
   let takePictureAction: UIAlertAction = UIAlertAction(title: "TakePhoto", style: .default) { action -> Void in
       //Code for launching the camera goes here
       self.openCameraPicker()
   }
   actionSheetController.addAction(takePictureAction)
   //Create and add a second option action
   let choosePictureAction: UIAlertAction = UIAlertAction(title: "ChooseFromLibrary", style: .default) { action -> Void in
       //Code for picking from Gallery  goes herece
       self.openPhotoGallery()
   }
   actionSheetController.addAction(choosePictureAction)
   //Present the AlertController
   self.present(actionSheetController, animated: true, completion: nil)
   }
   func openCameraPicker() {
   picker.sourceType = UIImagePickerController.SourceType.camera
   picker.cameraCaptureMode = .photo
   picker.modalPresentationStyle = .fullScreen
   present(picker,animated: true,completion: nil)
   }
  func openPhotoGallery() {
   picker.sourceType = .photoLibrary
   picker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
   present(picker, animated: true, completion: nil)
   }
  // MARK: - UIImagePickerControllerDelegate Methods
  func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
   if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
       //pickedImage  = image
       imgPick.image = image
   }
   dismiss(animated: true, completion: nil)
  }
 func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
   dismiss(animated: true, completion: nil)
 }
我已经通过给出断点检查了崩溃点,当涉及到
openPhotoGallery()
时,它就会崩溃

UIViewAlertForUnsatifiableConstraints可在调试器中捕获此信息

中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法也可能会有所帮助


请帮我查一下密码。也可以从iPad多媒体资料中获取图片。

对于iPad,请添加代码:

(在
let actionSheetController:UIAlertController=UIAlertController(标题:nil,消息:nil,首选样式:.actionSheet)下)
行)


希望它能帮助你……

self。你的视图意味着你的按钮所在的区域是什么。你可以写self.view@谢谢你,我用了我的
contentView
来代替
yourView
嘿,请给我一个建议,我正在用xcode ios 13.02版制作应用程序,但我想在iPad OS 11.0版中测试这个应用程序,并在apple开发者帐户中添加它的UDID。有可能吗??can应用程序将安装在iPad操作系统11.0版中是的,您应该将带有iOS 11的iPad添加到您的模拟器中。
actionSheetController.popoverPresentationController?.sourceView = self.yourView