gpt4 book ai didi

ios - 在 UIImagePickerController 中添加左 UIBarButton

转载 作者:行者123 更新时间:2023-11-29 01:16:27 25 4
gpt4 key购买 nike

我想在 .PhotoLibrary 我的左侧栏项目中添加一个相机选项我的代码如下所示,但它们不起作用。

let picker = UIImagePickerController()

let camera = UIBarButtonItem(barButtonSystemItem: .Camera, target: self, action: Selector("btnOpenCamera"))
picker.navigationItem.leftBarButtonItem = camera

picker.allowsEditing = true
picker.sourceType = .PhotoLibrary
picker.delegate = self

presentViewController(picker, animated: true, completion: nil)

最佳答案

您不能按照现在的方式执行此操作,因为没有 UINavigationControllerUIImagePickerController。为此,您必须在您的类中添加 UIInavigationControllerDlegate 方法。

将此方法添加到您的 viewController

 func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
print("m in")

viewController.navigationItem.title = "Home"
let camera = UIBarButtonItem(title: "camera", style: .Plain, target:self, action: "btnOpenCamera")
viewController.navigationItem.leftBarButtonItem = camera

输出是这样的: enter image description here

关于ios - 在 UIImagePickerController 中添加左 UIBarButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35122588/

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