在UIImagePickerController中添加左UIBarButton

时间:2016-02-01 03:27:07

标签: ios swift uiimagepickercontroller

我想在 <script id="blogs-tpl" type="text/x-handlebars-template"> {{#each blog}} <div class="col s12 m4"> <div class="icon-block"> <p><center><div class="fade-in one"><a class="view" href="{{image.url}}"><img style="width: 250px; height: 375px;" src="{{image.url}}"></a></div> <div><span class="typcn typcn-heart" style="color: red; font-size: 20px;"></span> {{likesCount}} &nbsp; <span class="typcn typcn-tags" style="color: #000; font-size: 20px;"></span> ${{price}}</div> <div>Designed by {{author.objectId}}</div><br> <a href="" id="download-button" class="btn-large waves-effect waves-light indigo darken-2">Details</a></center></p> </div> </div> {{/each}} </script> 我的代码中的左侧条形项目中添加一个相机选项,如下所示,它们无法正常工作。

.PhotoLibrary

2 个答案:

答案 0 :(得分:1)

您不能按照自己的方式执行此操作,因为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

中添加此方法
requests

输出如下: enter image description here

答案 1 :(得分:0)

提到这个post,并从目标C解释为Swift。

我找到了解决问题的方法。此方法将在加载的视图控制器中执行我需要的任何自定义。

func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {

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