单击编辑按钮后显示添加按钮?

问题描述:

我有一个顶部导航栏控件的视图。视图处于第二级,默认情况下在左侧显示“后退”按钮。在我看来类,我添加右侧的默认导航编辑按钮:单击编辑按钮后显示添加按钮?

self.navigationbarItem.rightButtonItem = self.editButtonItem; 

与这行代码,编辑按钮位于右侧,当点击它时,示图(表视图)在每行左边的删除标记变为可编辑。之后,编辑按钮的标题变成“完成”。所有这些都是通过内置在导航控件中的默认编辑按钮完成的,我想。

我想在左边添加一个添加按钮,或者在单击编辑时替换“后退”按钮。我想我必须在我的视图类中实现某种委托。这将提供一个位置来插入我的代码,以在单击编辑按钮时在左侧添加添加按钮,并在完成按钮被单击时恢复“返回”按钮。如果是这样,代表是什么?或者还有其他方法可以实现吗?

我做这样的(在我的表视图控制器):

editButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(toggleEditing)]; 
    editButton.possibleTitles = [NSSet setWithObjects:@"Edit", @"Done", nil]; 
    self.navigationItem.rightBarButtonItem = editButton; 


- (void)toggleEditing { 
    // Keep track of whether your editing or not here 
    // and show/hide the 'add' button accordingly 
} 
+0

它看起来像您添加自定义的按钮。删除标记的默认行为如何?任何方式来设置在编辑模式下的表格视图? – 2010-04-04 05:10:30

+0

使用setEditing:animated:方法在编辑模式下设置表视图。 – glorifiedHacker 2010-04-04 06:25:15