-1
我有一个带有三个自定义(Xib)单元的UITableview。我静态加载了cellForRowAtIndexPath中的每个单元格。每个单元格包含添加按钮以在下一行插入新行。当我插入新行时,它会显示另一个Xib单元而不是预期的单元格,并且还会在所有节中添加新行。如何在Objective C中解决它?
注:冲突
1)单元格静态加载。
2)但动态插入单元格。
3)在numberOfRowsInSection方法中,使用数组(NSMutableArray)count给出的count个计数。
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ if (indexPath.row==0)
{
CustomCellA *aCell = [tableView dequeueReusableCellWithIdentifier:@"ACell"];
return aCell;
} else if(indexPath.row==1)
{
CustomCellB *bCell = [tableView dequeueReusableCellWithIdentifier:@"BCell"];
return bCell;
}else
{
CustomCellC *cCell = [tableView dequeueReusableCellWithIdentifier:@"CCell"];
return cCell;
}
}
-(void)insertNewACell:(UIButton *)addButton atIndexPath:(NSIndexPath *)addBtnIndexPath
{
newArray = [[NSMutableArray alloc]init];
[newArray addObject:@"XXXX"];
[newArray addObject:@"YYYY"];
[newArray addObject:@"YYYY"];
[sectionRowItems addObject:newArray];
[sectionRowItems insertObject:newArray atIndex:addBtnIndexPath.row];
[self.numericTable reloadData];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return alphabetArray.count
}
谢谢您的建议来管理部分。好友我如何管理cellForRowAtIndexPath当我插入新行,如上所述。 –
你可以应用像numberOfRowsInSection这样的条件,就像我在我的回答中一样。 –
对不起,如果你想为每个部分使用同一个单元格,你不需要在cellForRowAtIndexPath中做任何修改。 –