Ios 在UITableview的指定索引路径行中插入新行时发生冲突

Ios 在UITableview的指定索引路径行中插入新行时发生冲突,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个带有三个自定义(Xib)单元格的UITableview。我在cellForRowAtIndexPath中静态加载了每个单元格。每个单元格都包含“添加”按钮,用于在下一行插入新行。当我插入新行时,它显示另一个Xib单元格,而不是预期的单元格,并且在所有部分中添加新行。如何在目标C中解决它? 注意: 1) 静态加载的单元 2) 但是动态插入单元 3) 在numberOfRowsInSection方法中,使用数组(NSMutableArray)计数指定行数 首先,您要在else部分中设置Cus

我有一个带有三个自定义(Xib)单元格的UITableview。我在cellForRowAtIndexPath中静态加载了每个单元格。每个单元格都包含“添加”按钮,用于在下一行插入新行。当我插入新行时,它显示另一个Xib单元格,而不是预期的单元格,并且在所有部分中添加新行。如何在目标C中解决它?
注意:

1) 静态加载的单元

2) 但是动态插入单元

3) 在numberOfRowsInSection方法中,使用数组(NSMutableArray)计数指定行数


首先,您要在else部分中设置
CustomCellC
。因此,当您添加新单元格时,如果单元格
indexath.row
大于1,则使用
CustomCellC

可能您对所有部分使用相同的数组。因此,当您在数组中插入新对象时,
numberOfRowsInSection
将为每个节返回相同的计数,并在每个节中添加新行

您可以为每个节设置不同的数组,也可以为特定节设置行数,如下所示:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if (section == 0){
        return arr.count; 
    }else if (section == 1{
        return arr1.count;
    }

    return arr2.count;
}

-(void)insertNewACell:(UIButton *)addButton atIndexPath:(NSIndexPath *)addBtnIndexPath
{

    newArray = [[NSMutableArray alloc]init];
   [newArray addObject:@"XXXX"];
   [newArray addObject:@"YYYY"];
   [newArray addObject:@"YYYY"];

   if(addBtnIndexPath.section)
    [arr addObject:newArray]
   }else if(addBtnIndexPath.section){
    [arr1 addObject:newArray]
   }else{
    [arr addObject:newArray]
   }

感谢您对管理部门的建议。老兄,当我如上所述插入新行时,我如何管理CellForRowatineXpath。您可以像我在回答中所做的那样,应用numberOfRowsInSection之类的条件。对不起,如果您希望每个节都使用相同的单元格,则无需对CellForRowatineXpath进行任何更改。
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if (section == 0){
        return arr.count; 
    }else if (section == 1{
        return arr1.count;
    }

    return arr2.count;
}

-(void)insertNewACell:(UIButton *)addButton atIndexPath:(NSIndexPath *)addBtnIndexPath
{

    newArray = [[NSMutableArray alloc]init];
   [newArray addObject:@"XXXX"];
   [newArray addObject:@"YYYY"];
   [newArray addObject:@"YYYY"];

   if(addBtnIndexPath.section)
    [arr addObject:newArray]
   }else if(addBtnIndexPath.section){
    [arr1 addObject:newArray]
   }else{
    [arr addObject:newArray]
   }