UITableview edit/done button(UITableview 编辑/完成按钮)
问题描述
我在顶部有一个表格视图和导航栏.
I have a tableview and navigation bar on the top.
我的导航栏左侧有一个编辑按钮,其中包含以下代码行.
I have a Edit button on the left of my navigation bar with the following line of code.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
当我点击编辑按钮时,它变为完成按钮.到目前为止一切都很好.
When i click on the edit button, it changes to done button. All is fine so far.
如果我想在点击完成按钮时做一个小操作,我应该在哪里添加代码?
Where do i add code, if i want to do a small operation when the Done button is clicked.?
推荐答案
一旦你用 self.editButtonItem.action = @selector(editClicked:);
你应该做的是在你自己的控制器类中重写 UIViewController 的 setEditing 方法:
What you should do is override UIViewController's setEditing method in your own controller class:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
if(editing == YES)
{
// Your code for entering edit mode goes here
} else {
// Your code for exiting edit mode goes here
}
}
您还需要在情节提要中将 UIBarButtonItem 设置为编辑",或者如果您更喜欢在代码中执行此操作,请使用以下代码:
You also need to set your UIBarButtonItem to "Edit" in storyboard or if you prefer doing it in code use the following:
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
editButtonItem 是系统已经为您设置的辅助属性.
editButtonItem is a helper property already set by the system for your comfort.
这篇关于UITableview 编辑/完成按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UITableview 编辑/完成按钮
基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
