UITableView数据重装问题

时间:2010-08-18 05:13:16

标签: objective-c uitableview

我正在使用UITableViewController子类,当用户触摸“开始会话”时,该子类应该来自“登录表”(包含用户名和密码的UITextField以及开始会话单元格的表) “应该重新加载UITableViewController的单元格,只显示一个带有”Log Out“标签的单元格。

问题在于,当我重新加载信息时,某些单元格似乎被“选中”(如蓝色),而某些单元格没有它们应该的标题。

我正在以这种方式重新加载表格:

    [[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];

根据我正在重新加载哪个表格,Ranges会改变,但这是基本的想法,是否有我遗漏的东西?

1 个答案:

答案 0 :(得分: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];

这些方法的组合似乎有效,我不知道,我不喜欢它,在我找到更好的解决方案之前会这样做。