【发布时间】:2017-02-07 03:56:23
【问题描述】:
我正在使用 Swift 3、Xcode 8.2。我有一个自定义表格视图单元(称为 MyCustomCell),其中有一个图像视图和一个按钮,单击该按钮可打开相机。用户可以添加更多这些单元格。我希望用户能够点击一个按钮、拍照,然后将其显示在该按钮的相应图像视图中。
我的问题是,现在它总是出现在第一个图像视图中,而不是其他图像视图中。
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let pickedImage : UIImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
let scancell = tableView.cellForRow(at: NSIndexPath(row: 0, section: 0) as IndexPath) as! MyCustomCell // it's this line that is wrong
scancell.imgView.contentMode = .scaleAspectFit
scancell.imgView.image = pickedImage
scancell.cameraButton.isHidden = true
};
self.dismiss(animated: true, completion: nil)
}
我很难理解 imagePickerController 是如何被调用的,以及我是否可以传入用户单击的自定义单元格。
我想做这样的事情:
tableView.cellForRow(at: tableView.indexPath(for: cell))
cell 以某种方式传递到参数中,但我不确定imagePickerController 的签名是否可以修改,如果可以,它是如何调用的?
任何帮助将不胜感激。谢谢!
【问题讨论】:
标签: ios swift xcode swift3 uiimagepickercontroller