【发布时间】:2013-11-30 20:08:59
【问题描述】:
我正在使用UISegmentedControl 在两个数据集之间切换UITableView(想想最喜欢的和最近的)。点击分段控件会使用不同的数据集重新加载 tableview。
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:anim];
当用户滑动删除一行时,它可以正常工作。 HOWEVER 当用户通过分段控件切换数据集时,DELETED CELL 会在不改变其外观的情况下被重新使用(即红色的“DELETE”按钮仍然存在并且行内容无处可见) .这似乎与大多数人看到的相反问题是删除按钮没有出现。
这是删除代码:
- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
if ([self.current isEqualTo:self.favorites])
{
Favorite *fav = self.favorites[indexPath.row];
NSMutableArray *mut = [self.favorites mutableCopy];
[mut removeObjectAtIndex:indexPath.row];
self.favorites = mut;
self.current = self.favorites;
[self.tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
}
tableview 设置为单选,self.tableView.editing == NO。我还尝试使用[self.tableView reloadData] 并删除/插入从一个数据集到下一个数据集的行差异。两者都不起作用。
我使用的 UITableViewCell 没有 backgroundView 或 selectedBackgroundView
[编辑]
分段控制值已更改:
- (IBAction)modeChanged:(id)sender
{
if (self.listMode.selectedSegmentIndex == 1)
{
self.current = self.favorites;
}
else
{
self.current = self.recents;
}
// Tryin this:
[self.tableView reloadData];
// Tried this:
// [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
}
// Only 1 Section per table
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
return [self.current count];
}
【问题讨论】:
-
更新您的问题以包含您处理分段控件中的更改和重新加载表格的代码。
-
@rmaddy 我已经添加了代码 - 它相对简单。
-
尝试在调用
reloadData之前调用self.editing = NO -
self.editing永远不会改变......它总是NO -
这是
UITableViewController吗?是self.editing没有设置然后检查self.tableView.editing。
标签: ios uitableview ios7