gpt4 book ai didi

Swift:从自定义单元启动相机

转载 作者:行者123 更新时间:2023-11-28 13:18:10 24 4
gpt4 key购买 nike

我有一个自定义单元格,里面有一个按钮。点击该按钮后,我想启动相机。

自定义单元格 Xib:

enter image description here

//自定义按钮单元格类代码:

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'
}
}

错误:这个“CameraCell”没有名为“presentViewController”的成员

我还需要一个委托(delegate) (UIImagePickerControllerDelegate) 来处理拍照后的事件。

如何从自定义单元格内的按钮启动相机并将其设置为相机代理?

最佳答案

因为你是UITableViewCell的子类,怎么调用presentViewController。只有 UIViewController 可以调用它。

我要做的是在您处理单元格的 UIViewController 中处理 UIImageViewController 的触发器。

关于Swift:从自定义单元启动相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28036593/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com