0

我有一个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;

或者有没有更好的方法来做到这一点?我还想在编辑模式下更改“完成”文本。

4

2 回答 2

2

是的,如果你想要自定义标题,你必须这样做

- (void)setEditing:(BOOL)editing animated:(BOOL)animated;
于 2012-10-03T13:10:24.423 回答
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
        }
}

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

:)

于 2012-10-03T13:14:15.267 回答