我正在以编程方式在UITableViewCell内的UIImageView中添加一个按钮。但是,如何访问原始imageView,以便将所选图像设置为UIImageView?
我的代码:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = theTableView.dequeueReusableCellWithIdentifier("SampleCell") as! UITableViewCell
if indexPath.section == 2 {
let imageView = UIImageView(frame: CGRectMake(0, 0, 320, 175))
let button = UIButton(frame: CGRectMake(110, 30, 100, 100))
let myImage = UIImage(named: "Camera-50.png")
let touch = UITapGestureRecognizer()
imageView.addGestureRecognizer(touch)
imageView.layer.borderWidth = 0.5
button.setImage(myImage, forState: UIControlState.Normal)
button.addTarget(self, action: "getImage", forControlEvents: .TouchUpInside)
cell.addSubview(button)
cell.addSubview(imageView)
}
return cell
}
func getImage() {
let picker = UIImagePickerController()
picker.allowsEditing = true
picker.delegate = self
presentViewController(picker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
//need to access imageView to set image
}