ios - 从图库或相机中选择图像后 UIImage 未显示

标签 ios swift xcode uiimage uiimagepickercontroller

我正在尝试从相机或图库中选择图像,并在我的 ImageView 中将所选图像显示到屏幕上。但它没有显示。

  func imagePickerController(_ picker: UIImagePickerController,
                               didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

        guard let selectedImage = info[.originalImage] as? UIImage else {
            fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
        }

        imageview.image = selectedImage

        dismiss(animated: true, completion: nil)
    }

我错过了什么?

enter image description here

在我的例子中,断点函数根本没有被调用

最佳答案

如果您的断点函数不在调用时,那么我认为您还没有在 viewDidLoad() 中设置 imagePicker 委托(delegate)

override func viewDidLoad() {
     super.viewDidLoad()
     imagePicker.delegate = self   
   }

关于ios - 从图库或相机中选择图像后 UIImage 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54157346/

相关文章:

IOS,UIView,检测 subview 中的隐藏状态变化

c# - Unity 2018.1.3f1 UI 闪烁问题

ios - SpriteKit - didMovetoView 未被调用

iphone - iOS 应用程序可以使用哪些文件?

ios - 将 UITableViewController 添加到 SubView

iOS WKWebView 从点获取 RGBA 像素颜色

ios - 处理多个 UISlider

ios - 卸载 CalendarKit 后的高度/宽度属性问题

ios - 向 uisearchbar 添加刷新 Logo

ios - 错误: Missing argument for parameter #1 in call when I am calling a function from different class in Swift