我有一个内置按钮的自定义单元格。当点击该按钮时,我想启动相机。
自定义单元格Xib:
//自定义按钮单元格类 代码:
import UIKit
class CameraCell: UITableViewCell, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var buttonCamera: UIButton!
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
@IBAction func buttonCameraTapped(sender: UIButton) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
imagePicker.mediaTypes = [kUTTypeImage]
imagePicker.allowsEditing = false
self.presentViewController(imagePicker, animated: true,
completion: nil)
//This 'CameraCell' does not have a member named 'presentViewController'
}
}
错误:This 'CameraCell' does not have a member named 'presentViewController'
我还需要一个委托(UIImagePickerControllerDelegate)来处理拍摄照片后的事件。
如何从自定义单元格内的按钮启动相机并将其设置为Camera Delegate?
答案 0 :(得分:2)
因为您位于UITableViewCell
的子类中,所以如何调用presentViewController
。只有UIViewController
才能调用它。
我要做的是处理您处理单元格的UIImageViewController
中UIViewController
的触发器。