2010-08-18 113 views
1

我正在使用UITableViewController子类,该子类应该从“登录表”(包含UITextField的用户名和密码以及启动会话单元格的表),当用户触摸应该重新加载UITableViewController的“Start Session”单元,并且只显示一个带有“注销”标签的单元。UITableView数据重新加载问题

问题是,当我重新载入信息时,某些单元格显示为“被选中”(如蓝色),并且某些单元格没有标题。

我重装表是这样的:

[[self tableView] beginUpdates]; 
    [[self tableView] deleteSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 2)] withRowAnimation:UITableViewRowAnimationTop]; 
    [[self tableView] insertSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 0)] withRowAnimation:UITableViewRowAnimationTop]; 
    [[self tableView] endUpdates]; 

根据该表,我重装幅度会改变,但是这是最基本的理念,是有什么我失踪?

回答

1
[[self tableView] beginUpdates]; 
[[self tableView] deleteSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 0)] withRowAnimation:UITableViewRowAnimationBottom]; 
[[self tableView] insertSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 2)] withRowAnimation:UITableViewRowAnimationBottom]; 
[[self tableView] endUpdates]; 

[[self tableView] beginUpdates]; 
[[self tableView] reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 2)] withRowAnimation:UITableViewRowAnimationBottom]; 
[[self tableView] endUpdates]; 

[[self tableView] reloadData]; 

这种方法的组合似乎在工作,我不知道,我不喜欢它,会留下它,直到我找到更好的解决方案。

+0

也许我错过了这里的东西......你为什么不只调用[[self tableView] reloadData];跳过其他一切。 – maxpower 2011-03-10 20:19:22

+0

@maxpower这个动画很好。 – Moshe 2012-10-05 19:50:25