我在表格 View 中有一个注册表单,用户可以在该注册表单中选择个人资料图片。
如何使用所选图像更新 tableview 单元格中的图像?
我如何允许单元格。在不在 tableview 内的“func imagePickerController()”内?
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/