UITableview编辑/完成按钮 [英] UITableview edit/done button

查看:92
本文介绍了UITableview编辑/完成按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个tableview和顶部的导航栏。



我在导航栏左侧有一个编辑按钮,其中包含以下代码。

  self.navigationItem.leftBarButtonItem = self.editButtonItem; 

当我点击编辑按钮时,它变为完成按钮。一切都很好,到目前为止。



我在哪里添加代码,如果我想点击Done按钮时执行一个小操作。

self.editButtonItem.action = @selector(editClicked:); 覆盖它的默认动作时,按钮停止提交对你的控制器类的修改。 code>



你应该做的是在你自己的控制器类中覆盖UIViewController的setEditing方法:

   - (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{
[super setEditing:editing animated:animated]

if(editing == YES)
{
//您输入编辑模式的代码在这里
} else {
//您的代码退出编辑模式在这里
}
}

您还需要设置UIBarButtonItem在storyboard中编辑,或者如果你喜欢在代码中使用以下代码:

   - (void)viewDidLoad {
[super viewDidLoad];

self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

editButtonItem是系统已经设置的助手属性, p>

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.?

解决方案

The button stops committing the changes to your controller class once you override it's default action with self.editButtonItem.action = @selector(editClicked:);

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

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 is a helper property already set by the system for your comfort.

这篇关于UITableview编辑/完成按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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