在iOS中的自定义单元格上滑动删除

时间:2014-05-13 12:48:16

标签: ios uitableview

我正在使用滑动删除自定义单元格。对于一个特定的单元格,滑动功能不起作用。

我的自定义单元格显示“添加新值”。选择此选项后,会添加一些单元格,当我们滑动时,会出现删除选项。我想要的是滑动功能不适用于“添加新值”单元格。

2 个答案:

答案 0 :(得分:2)

检查tableView中的单元格类型:canEditRowAtIndexPath :,如果它不能编辑,则返回false。

所以在伪代码中

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
   NSInteger row = [indexPath row];
   // Check row type

   if(rowType==add_new_values_type) // YOU NEED TO WRITE THIS
   { 
     return false;
   }
   // Return YES - we will be able to delete the row
    return YES;
}

答案 1 :(得分:0)

你可以试试这个:

   - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
 {
    switch (indexPath.row) 
    {
      case 0: break; //assuming that your add cell is 1

      default:
          return UITableViewCellEditingStyleDelete; // rest of them you can delete
          break;
    }

}
相关问题