完成后,editButtonItem标题将重置为默认值

时间:2012-10-03 13:07:16

标签: iphone objective-c ios uitableview uinavigationcontroller

我有一个UINavigationControllerUITableView我正在使用editButtonItem来编辑UITableView

以下是代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.editButtonItem.title = @"تحرير";
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

首次启动时,会根据需要显示编辑按钮标题。但是当我点击它时,表视图进入编辑模式并显示Done。当我点按Done时,标题会重置为默认Edit

我是否必须在每个切换中设置标题:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated;

或者有更好的方法吗?我还想在编辑模式下更改“完成”文本。

2 个答案:

答案 0 :(得分:2)

是的,是的, 如果你想要自定义标题,你必须在

中进行
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;

答案 1 :(得分:0)

在.h文件中点击一个UIBarButtonItem

UIBarButtonItem *btnSave;

之后在.m文件中

-(void)viewWillAppear:(BOOL)animated
{
    btnSave = [[UIBarButtonItem alloc]init];
    btnSave.target = self;
    btnSave.action = @selector(btnEdit_Click:);
    btnSave.title = @"Edit";// here give title which you want...
    self.navigationController.topViewController.navigationItem.rightBarButtonItem = btnSave;
}

-(IBAction)btnEdit_Click:(id)sender
{
        if ([btnSave.title isEqualToString:@"Edit"]) {
              ///something do here and also change the title of button here
             [btnSave setTitle:@"Save"];// just for an example

        }
        else {
              ///something do here and also change the title of button here
              [btnSave setTitle:@"Edit"];//just for an example
        }
}

我希望这可以帮助你...

:)