У меня есть кнопка UITableViewCell, чтобы взять изображение и поместить его обратно в ячейку. Когда я называю UIImagePickerController и забрать/взять изображение, он должен вызвать следующую функциюUIImagePickerController (didFinishPickingMediaWithInfo) НЕ вызывается в UITableViewCell Swift
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject], sender:AnyObject)
По какой-то причине не называем эту функцию, поэтому, я не могу поместить выбранный UIImage к текущей ячейке. Любая помощь будет очень полезна.
Это код кнопки
@IBAction func takePhoto(sender: AnyObject) {
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
imagePickerController.allowsEditing = true
let actionSheet = UIAlertController(title: "Choose image souruce", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
actionSheet.addAction(UIAlertAction(title: "Take Image", style: UIAlertActionStyle.Default, handler: { (alert:UIAlertAction!) -> Void in
imagePickerController.sourceType = UIImagePickerControllerSourceType.Camera
self.presentViewController(imagePickerController, animated: true, completion: nil)
}))
actionSheet.addAction(UIAlertAction(title: "Photo Library", style: UIAlertActionStyle.Default, handler: { (alert:UIAlertAction!) -> Void in
imagePickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
self.presentViewController(imagePickerController, animated: true, completion: nil)
}))
actionSheet.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))
self.presentViewController(actionSheet, animated: true, completion: nil)
}
Это функция imagePickerController на didFinishPickingMediaWithInfo
The self.reloadData это функция, которая запускает UITableView и перезагрузить данные.
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject], sender:AnyObject) {
var btnPos: CGPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
//Gets the chosen cell indexPath
var indexPath: NSIndexPath = self.tableView.indexPathForRowAtPoint(btnPos)!
let currentCell:TableViewCell = tableView.cellForRowAtIndexPath(indexPath) as TableViewCell
let iamgePicked:UIImage = info[UIImagePickerControllerOriginalImage] as UIImage
currentCell.cellImageOulet.image = iamgePicked
picker.dismissViewControllerAnimated(true, completion: nil)
self.loadData()
}