ios - Swift 3 "didFinishPickingMediaWithInfo"用于 tableview 单元格内的图像

标签 ios swift uitableview swift3

我在表格 View 中有一个注册表单,用户可以在该注册表单中选择个人资料图片。

如何使用所选图像更新 tableview 单元格中的图像?

我如何允许单元格。在不在 tableview 内的“func imagePickerController()”内?

Click for code

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

if let orginalImage = info[UIImagePickerControllerOriginalImage] as? UIImage {

cell.profileImage.image = orginalImage

}

else { print ("error") }

picker.dismiss(animated: true, completion: nil)

}

最佳答案

只需在 didFinishPickingMediaWithInfo 方法中创建单元文件对象即可。

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


        //cell file object
        let cell = tblView.cellForRow(at: IndexPath.init(row: 0, section: 0)) as! ProfileTableViewCell //cell file object

        let imgTemp = info[UIImagePickerControllerOriginalImage] as? UIImage// get image from imagePickerViewController
        cell.imgViewProfile.image = imgTemp
        cell.imgViewProfile.layer.cornerRadius = cell.imgViewProfile.frame.size.width/2 // make image circle
        cell.imgViewProfile.layer.masksToBounds = true
        appDelegate.window?.rootViewController?.dismiss(animated: true, completion: nil)
    }

关于ios - Swift 3 "didFinishPickingMediaWithInfo"用于 tableview 单元格内的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45559174/

相关文章:

ios - 在哪些情况下可以 viewWillAppear(_ animated : Bool) method will not be called even that viewDidLoad() is already called?

swift - 如何在 Swift 中定义带有函数类型参数的函数

ios - NSFetchedResultsController-controllerDidChangeContent : - Attempt to create two animations for cell with userInfo

ios - 如果 navigationBar.translucent 为 NO,则 UITableView 底部区域保持在屏幕之外;

ios - CallKit 的 didActivate 到底什么时候被调用?

ios - 检测 UIButton 顺序?

ios - 当缩放或移动 iosmap 时,它总是跳回到用户位置 Swift

ios - UITableView 奇怪的分隔线颜色

ios - 如何在 CloudKit 记录中搜索部分单词?

ios - 在 Tableview 单元格内的 webview 上加载 HTML 内容需要太多时间?