讓我們奇怪的問題有兩個可變陣列,讓我們有下面的代碼:與[的tableView reloadData]
- (void)viewDidLoad
{
NSMutableArray *A = [[NSMutableArray alloc] init];
NSMutableArray *B = [[NSMutableArray alloc] init];
// fill up A
// B remains empty
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// ...
if (...)
{
// fill up the cell with datas of an object from A
}
else
{
// fill up the cell with datas of an object from B
}
//...
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (...)
{
// remove an object from A and put it in B
}
else
{
// remove an object from B and put in A
}
[tableView reloadData];
}
如果[的tableView reloadData]被註釋掉(// [的tableView reloadData]),比後按照預期,「點擊」表格不會失效。如果當前單元格再次滾動並在屏幕上再次滾動,則會調用「cellForRowAtIndexPath」,並根據從哪個數組獲取其內容的方式,將單元格「繪製」爲正確。 但是,如果[tableView reloadData]處於活動狀態,而「cellForRowAtIndexPath」根本沒有被調用(!)並且單元格從屏幕上被刪除!
反應:WHUT?
可以幫助我的任何人如何使桌面視圖無效(而不是通過滾動單元格和:))!
在此先感謝!
我會在didSelectRowAtIndexPath方法中更新受影響的單元格,而不是在那裏調用reloadData。 – onnoweb
您是否使用不同的單元格標識符? –
您是否嘗試過使用'delete/insertRowsAtIndexPaths:withRowAnimation'?只要你的數組匹配了這些變化,這應該會立即改變你的tableView而不需要調用'reloadData'。 – justin