Ios 如何在UITableView中保留两行的插入和删除中的滑动?

Ios 如何在UITableView中保留两行的插入和删除中的滑动?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,在我的UITableView中,有两行。我想为第一行添加编辑(插入) 对于第二行,我希望滑动以删除操作(我不希望使用红色减号按钮)。但我不能把这两个放在一起。 你能帮帮我吗?我的代码如下: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.tableView.editing = YES; } - (BOOL)tableVie

在我的UITableView中,有两行。我想为第一行添加编辑(插入)

对于第二行,我希望滑动以删除操作(我不希望使用红色减号按钮)。但我不能把这两个放在一起。 你能帮帮我吗?我的代码如下:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView.editing = YES;
}
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
 {
     // Return NO if you do not want the specified item to be editable.
     return YES;
 }

 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
 {
     if (editingStyle == UITableViewCellEditingStyleDelete) {
         // Delete the row from the data source


     }
     else if (editingStyle == UITableViewCellEditingStyleInsert) {
         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
     }
 }

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
     if (indexPath.row == 0) {
            return UITableViewCellEditingStyleInsert;
     }   

    return UITableViewCellEditingStyleNone;

}
我想如果你搬走

self.tableView.editing = YES;
然后你的问题就解决了。
我不太确定,但是试试看。并告诉我您得到的结果。

考虑将UISweepGestureRecognizer添加到单元格的内容视图中。它可能会解决你的问题。这样,您可以只保留第一行的编辑样式,并对其他行进行滑动删除。但为此,我必须自定义删除操作。对吗?SwipeGestureRecognitor的工作原理就像一个按钮。它将调用一个函数,您可以在该函数中删除特定单元格。如果你愿意,我可以给你一些代码,可能会有所帮助。谢谢,这是个好主意。但是如果有可能像内置的delete操作一样出现delete按钮,那么最好首先更改:returnuitableviewcelleditingstylenone;至:返回UITableViewCellEditingStyleDelete;检查是否有效。此外,还必须实现删除代码。否。当我删除该行时,加法符号也消失了。我想这可能有助于您不显示红色减号按钮。这是感谢信。当只有一个删除单元格时,它工作得非常完美。但我也需要一个插入单元。所以当我设置编辑“否”时,插入也设置为“否”