gpt4 book ai didi

ios - 当前 ImagePickerView 导致崩溃

转载 作者:搜寻专家 更新时间:2023-11-01 07:19:40 25 4
gpt4 key购买 nike

这是我的代码,一个简单的类,其中包含一个在 Storyboard 中创建的 View ,其中包含一个用于显示 imagePickerView 的按钮。显示 imagePickerView,然后应用程序崩溃并显示 libc++abi.dylib: terminating with uncaught exception of type NSException

import Foundation
import UIKit


class ImageSelectionView: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {


override func viewDidLoad(){
super.viewDidLoad()
}

@IBAction func backButtonTapped(_ sender: AnyObject) {
self.navigationController?.dismiss(animated: true, completion: nil)
}


@IBAction func openPhotoLibrary(_ sender: AnyObject) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary;
imagePicker.allowsEditing = true
present(imagePicker, animated: true, completion: nil)
self.present(imagePicker, animated: true, completion: nil)
}
}


func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
self.dismiss(animated: true, completion: nil);
}




}

无法弄清楚哪里出了问题,任何帮助都会很棒,谢谢!

最佳答案

要访问照片库,您需要将 Privacy - Photo Library Usage Description 放入应用程序的 .plist 文件中,并附上一些说明,

如图所示

enter image description here

特别是在您的代码中,您编写了代码来两次呈现相同的 imagePicker,如下所示。

    present(imagePicker, animated: true, completion: nil)
self.present(imagePicker, animated: true, completion:

所以我建议保留一个,可能是
present(imagePicker, animated: true, completion: nil)

self.present(imagePicker, animated: true, completion:nil)

希望对您有所帮助。

快乐编码......

关于ios - 当前 ImagePickerView 导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39928251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com