【发布时间】:2017-01-24 13:53:45
【问题描述】:
我想将图像设置为自定义单元格。我很困惑如何做到这一点。 假设我的 UITable 视图中有一个自定义单元格。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CustomCellOne", forIndexPath: indexPath) as! CustomOneCell
let tapGestureRecognizer = UITapGestureRecognizer(target:self, action:#selector(imageTapped(img:)))
cell.imageView.isUserInteractionEnabled = true
cell.imageView.addGestureRecognizer(tapGestureRecognizer)
return cell
}
现在,只要我点击图像,就会调用以下函数:
func imageTapped(img: AnyObject){
print("Image clicked.")
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
let imageData: NSData = UIImagePNGRepresentation(myImage)
let image: UIImage = UIImage(data:imageData,scale:1.0)
print(image)
//i am uploading the photo from here. and i want to set this picture to my cell imageView.
}
dismissViewControllerAnimated(true, completion: nil
}
我很困惑如何从这里调用单元格图像视图? 我该如何进一步处理?我只需要将获得的图像设置为单元格中的 imgeView 其他一切正常..
【问题讨论】:
-
您添加的代码可能在
didFinishPickingMediaWithInfo内,而不是在您的 Tapgesture 方法内。 -
这里一切正常。我可以选择图像,但没有明白如何在单元格图像视图中设置
-
这里一切正常。我可以选择图像,但没有明白如何在单元格图像视图中设置..是的,它在里面..
标签: ios swift uitableview uiimageview