【发布时间】:2020-09-25 14:59:09
【问题描述】:
我试图让用户选择一个图像并将其设置为那里的个人资料页面上的横幅,但是当我编写我的代码时,我在尝试呈现 imagePicker 时不断收到错误“在范围内找不到'存在'”并且在尝试关闭 imagePicker 时,我还会收到“无法在范围内找到 'dismiss'”
这是我上面的代码:
//this function gets called when the user tapes on the banner to change the image
class ProfileHeader: UICollectionViewCell, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@objc func handleBannerTapped() {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.allowsEditing = true
present(imagePicker, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard let bannerPicture = info[UIImagePickerController.InfoKey.editedImage] as? UIImage else {
imageSelected = true
return
}
imageSelected = true
profileImage.layer.masksToBounds = true
profileBanner.setImage(bannerPicture.withRenderingMode(.alwaysOriginal), for: .normal)
dismiss(animated: true, completion: nil)
}
}
我在我的注册页面中使用了相同的功能,用户可以在其中选择个人资料图片并且它工作正常,所以我很困惑为什么它现在不适用于横幅
【问题讨论】:
-
代码在哪里?我希望在
UIViewController中。只有UIViewController可以拨打present(_:animated:completion:) -
您需要编辑您的问题以显示该代码来自哪个类。包括类声明:例如
class myVCClass: UIViewController { <functions> }
标签: swift uiimagepickercontroller