-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中做任何修改。 –