首页 文章

UITableview部分可编辑

提问于
浏览
0

在我的tableview中有5个部分1)1和2不可编辑而3,4和5可编辑在第1部分使用复选框,2个单选框,3个插入单元格,4个删除单元格,5个移动单元格

所以对于最后3我希望我的tableview将是可编辑的,并且 - 将在单元格的开头显示 .

而不是对于forst 2部分 . 我试过 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

但这不起作用 . 有什么帮助吗?

2 回答

  • 0

    你在 tableView:canEditRowAtIndexPath: 的正确轨道上 . 您还需要实现tableView:editingStyleForRowAtIndexPath: .

    另外,您是否在UITableView上调用setEditing:animated将表格置于编辑模式?我认为你是,但是仔细检查就不会受到伤害 .

  • 5
    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
     {
     // Return NO if you do not want the specified item to be editable.
    
      NSInteger section = [indexPath section];
      if (section ==0)
        return NO;
      if (section ==1)
        return NO;
      if (section ==2)
        return YES;
      if (section ==3)
        return YES;
      if (section ==4)
        return YES;
    
    
     }
    
    
    
    - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    
        [super setEditing:editing animated:animated];
        [self.tableView setEditing:editing animated:animated];
        [tableView reloadData];
    }
    

相关问题