gpt4 book ai didi

swift - 无法更新tableview + uiimagepickerController中的头像

转载 作者:行者123 更新时间:2023-11-30 10:35:09 25 4
gpt4 key购买 nike

我有一个带有 imageView 头像的 tableViewcell,我在 viewController 中使用 TapGestureRecognizer 来更改头像,但在我选择照片后,我的头像仍然没有照片。只是白色。也许我应该重新加载一些东西?

我有带有 imageView 的单元格,并且在 viewController 中使用 TapGestureRecognizer 来更改头像,但是在我选择照片后,我的头像仍然没有照片。只是白色。也许我应该重新加载一些东西?

Image of viewcontroller

extension BarberSettingsViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
var selectedImageFromPicker: UIImage?
if let editedImage = info[.editedImage] as? UIImage {
selectedImageFromPicker = editedImage
picker.dismiss(animated: true, completion: nil)
} else {
let originalImage = info[.originalImage] as! UIImage
selectedImageFromPicker = originalImage
picker.dismiss(animated: true, completion: nil)
}

if let selectedImage = selectedImageFromPicker {
let cell = tableView.dequeueReusableCell(withIdentifier: UserAvatarCell.name) as! UserAvatarCell
cell.avatarImageView.image = selectedImage
}
}


func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.dismiss(animated: true, completion: nil)
}
}

最佳答案

在 viewdidLoad() 上方声明此代码

var img:UIImage? { 已设置{

        tableView.reloadData()
}
}

然后在 table view 的 cellForRow 方法上添加这一行

cell.imageView.Image = img

并更改此功能

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { var selectedImageFromPicker: UIImage? 如果让editedImage = info[.editedImage]为?用户界面图像 { selectedImageFromPicker = 已编辑的图像 picker.dismiss(动画:true,完成:nil) } 别的 { 让originalImage = info[.originalImage]为!用户界面图像 selectedImageFromPicker = 原始图像 picker.dismiss(动画:true,完成:nil) }

    if let selectedImage = selectedImageFromPicker {
img = selectedImage

}
}

关于swift - 无法更新tableview + uiimagepickerController中的头像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58197177/

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