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

时间:2010-04-04 03:48:22

标签: iphone

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

self.navigationbarItem.rightButtonItem = self.editButtonItem;

使用这行代码,右侧有一个编辑按钮,当单击它时,视图(表格视图)变为可编辑,每行左侧有删除标记。之后,编辑按钮的标题变为“完成”。所有这些都是通过导航控件中内置的默认编辑按钮完成的。我认为。

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

1 个答案:

答案 0 :(得分:1)

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

    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
}