gpt4 book ai didi

ios - 发现扩展时遇到 Swift 4 错误 - 照片无法在 UI 上加载

转载 作者:行者123 更新时间:2023-11-28 12:03:59 25 4
gpt4 key购买 nike

当我从照片库中选择一张照片来填充 XCode 9.2 中的 UIImageView 时,我收到以下错误消息:

  • [发现] 发现扩展时遇到的错误:Error Domain=PlugInKit Code=13 "query cancelled"UserInfo={NSLocalizedDescription=query cancelled}

模拟器能够访问照片库并且我能够查看照片以进行选择,但是当我单击“选择”选项以选择照片时,会抛出错误并且在选择器被关闭后图像未填充 UIImageView。

我已经搜索了 Stack Overflow,如果执行此步骤,我能够摆脱错误消息:从 Xcode 菜单打开:产品 > 方案 > 编辑方案 > 在您的环境变量上,在值集禁用中设置 OS_ACTIVITY_MODE。但是,这只能消除错误,并不能解决我选择的照片未填充 UIImageView 的问题。我是 Swift 和 Xcode 的新手,被卡住了!请帮忙!

这是我的代码:

import UIKit

class HomeVC: UIViewController, UINavigationControllerDelegate,
UIImagePickerControllerDelegate {

@IBOutlet weak var avaImg: UIImageView!
@IBOutlet weak var usernameLbl: UILabel!
@IBOutlet weak var fullnameLbl: UILabel!
@IBOutlet weak var emailLbl: UILabel!

override func viewDidLoad() {
super.viewDidLoad()

//get user details from user global var (from database)
let username = (user!["username"] as? String)?.uppercased()
let fullname = user!["fullname"] as? String
let email = user!["email"] as? String
let ava = user!["ava"] as? String

//populate labels on view
usernameLbl.text = username
fullnameLbl.text = fullname
emailLbl.text = email


}

@IBAction func edit_click(_ sender: AnyObject) {

//select ava
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = UIImagePickerControllerSourceType.photoLibrary
picker.allowsEditing = true
self.present(picker, animated: true, completion: nil)

//selected image
func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let image = info[UIImagePickerControllerEditedImage] as?
UIImage
avaImg.image = image

self.dismiss(animated: true, completion: nil)
}

}
}

最佳答案

两个问题:

  • didFinishPickingMediaWithInfo 的签名是错误的。在 Swift 3+ 中是

    func imagePickerController(_ picker: UIImagePickerController, 
    didFinishPickingMediaWithInfo info: [String : Any])
  • 委托(delegate)方法必须在类的顶层(不能在另一个方法中)

    @IBAction func edit_click(_ sender: Any) {

    //select ava
    let picker = UIImagePickerController()
    picker.delegate = self
    picker.sourceType = .photoLibrary
    picker.allowsEditing = true
    self.present(picker, animated: true, completion: nil)
    }

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

    //selected image
    let image = info[UIImagePickerControllerEditedImage] as? UIImage
    avaImg.image = image
    self.dismiss(animated: true, completion: nil)
    }

关于ios - 发现扩展时遇到 Swift 4 错误 - 照片无法在 UI 上加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49733003/

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