我有一個數量的基本tableview在那加按鈕,將在tableview中添加新項目。
雖然我嘗試添加或刪除tableview中的部分並重新加載該tableview它會多次閃爍舊記錄,然後添加或刪除該部分。
這裏是代碼。UITableview插入/刪除
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SymbolTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([selectIndexPath containsObject:[NSNumber numberWithInt:(int)indexPath.section]])
{
[selectSymbol removeObject:cell.lblsymbol.text];
[selectIndexPath removeObject:[NSNumber numberWithInt:(int)indexPath.section]];
}
else
{
NSString *strr = cell.lblsymbol.text;
[selectSymbol addObject:strr];
[selectIndexPath addObject:[NSNumber numberWithInt:(int)indexPath.section]];
}
[tblDetail reloadData];
}
是什麼問題?
**永不**從視圖(表格視圖單元格)獲取像'cell.lblsymbol.text'這樣的信息,從模型(數據源數組)中獲取** always ** – vadian
怎麼樣?我沒有主意。 –
您應該使用'reloadRowsAtIndexPaths'或'reloadSections'和'insert/deleteRowsAtIndexPaths'方法。這樣它就不會再重新載入整個表格,只需重新載入表格的所需部分。 –