【问题标题】:editButtonItem title resets to default when Done完成后,editButtonItem 标题重置为默认值
【发布时间】:2012-10-03 13:07:16
【问题描述】:

我有一个UINavigationController,其中有UITableView,我正在使用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;

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

【问题讨论】:

    标签: iphone objective-c ios uitableview uinavigationcontroller


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      在 .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
              }
      }
      

      希望对你有帮助……

      :)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-31
        • 1970-01-01
        • 2015-09-09
        • 2019-10-06
        • 2017-07-24
        • 2018-12-04
        相关资源
        最近更新 更多