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

查看:21
本文介绍了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 编辑/完成按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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