【问题标题】:customising default Navigation edit button(How do i maintain its state ?)自定义默认导航编辑按钮(如何维护其状态?)
【发布时间】:2013-05-24 07:03:05
【问题描述】:

我有一个导航栏,我在上面设置了一个默认的编辑按钮,可以让我删除表格项目。但是,当我的表为空时,它仍将按钮的状态保持为“完成”并且不会返回“编辑” 我的代码在这里, 在 viewDidLoad

 self.navigationItem.leftBarButtonItem = self.editButtonItem;
 //My Editing method 
-(void)setEditing:(BOOL)editing animated:(BOOL)animated
 { 
    if([userInfoArr count]!=0)
    {
        [super setEditing:editing animated:animated];
        [self.tableView setEditing:editing animated:YES]; 
    }
 }

【问题讨论】:

  • 我的代码放在这里,在viewDidLoad self.navigationItem.leftBarButtonItem = self.editButtonItem;我的编辑方法-(void)setEditing:(BOOL)editing animated:(BOOL)animated { if([userInfoArr count]!=0) { [super setEditing:editing animated:animated]; [self.tableView setEditing:editing animated:YES]; } }
  • @jgdGuy..使用编辑选项并将代码添加到问题
  • 所以你想在所有项目都被删除后自动取消编辑模式?
  • @LithuT.V 会处理它....
  • @Wain yeaaa 我想自动取消编辑模式..!

标签: ios uitableview uinavigationbar uinavigationitem


【解决方案1】:

您可以在tableView:commitEditingStyle:forRowAtIndexPath: 方法中执行此操作,如下所示:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Do the deletion...
    }

    // If the array is empty, turn off edit mode
    if ([userInfoArr count] < 1) {
        [super setEditing:NO animated:NO];
        [tableView setEditing:NO animated:NO]; 
    }
}

【讨论】:

    【解决方案2】:

    然后你删除最后一个表项只是调用

    [self.tableView setEditing:NO animated:YES];
    

    在非编辑模式下设置表格视图。

    也许您需要调用[super setEditing:NO animated:YES]; 将按钮设置为“编辑”状态

    【讨论】:

    • 真棒它的工作原理..!我必须把它放在我的 numberOfRowsInSection 中,- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if(userInfoArr.count==0) { [self.tableView setEditing:NO animated:YES]; [super setEditing:NO animated:YES]; } return userInfoArr.count; }
    【解决方案3】:

    太棒了,它有效..!我必须把它放在我的 numberOfRowsInSection 中,- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if(userInfoArr.count==0) { [self.tableView setEditing:NO animated:YES]; [super setEditing:NO animated:YES]; } return userInfoArr.count; }

    【讨论】:

      【解决方案4】:

      我也遇到了这个问题。我解决了这个我的小技巧

      - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
      

      检查数据源是否为空。设置编辑为NO

       [self.tableView setEditing:NO animated:YES];
       [self setEditing:NO];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-14
        相关资源
        最近更新 更多