如何在运行时在UINaviagationBar中更改UIBarButtonItem的类型? [英] How to change UIBarButtonItem's type in UINaviagationBar at runtime?

查看:79
本文介绍了如何在运行时在UINaviagationBar中更改UIBarButtonItem的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究iPhone的视图,该视图由3个元素组成:UITextView,带有UIBarButtonItem的UIToolBar.

I am working on an iPhone's view which composed 3 elements, UITextView, UIToolBar with an UIBarButtonItem.

目标是,我希望UIBarButtonItem将其样式从编辑"(UIBarButtonSystemItemEdit)更改为完成"(UIBarButtonSystemItemDone),并将新的选择器更新为新方法.

The goal is, I want UIBarButtonItem change its style from 'edit' (UIBarButtonSystemItemEdit) to 'Done' (UIBarButtonSystemItemDone) and update new selector to new method.

首先,我尝试了以下代码,但是它不起作用:

First of all, I have tried following code but it doesn't work:

您能帮我这个想法吗?

Could you help me on this idea?

推荐答案

有一个内置的带有此行为的栏按钮,您可以通过UIViewContoller的editButtonItem属性获得它.轻按该按钮会将其从原来的视图控制器更改为编辑模式,然后将其切换为完成按钮.

There is a builtin bar button with this behaviour, you get it via the editButtonItem property of a UIViewContoller. Tabbing that button will change the view controller it came from into editing mode, and toggle the button into a done button.

- (void)viewDidLoad {
  [super viewDidLoad];
  self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

这篇关于如何在运行时在UINaviagationBar中更改UIBarButtonItem的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆