Xcode 以编程方式删除带有动画的单元格
Xcode remove cell with animation programmatically
您好,我一直在寻找一种方法来删除带有动画的静态单元格,但我还没有找到解决问题的方法。
我也试过:[tableView deleteRowsAtIndexPaths:[self.taskArray objectAtIndex:indexPath.row] withRowAnimation:UITableViewRowAnimationFade];
但没有成功。
由于您的 tableview 是静态的,因此您不能使用 deleteRowsAtIndexPath
。最好的选择可能是将您的数据迁移到表视图的数据源方法中。
如果这不可能,那么this answer ("UITableView set to static cells. Is it possible to hide some of the cells programmatically?")给出最好的方法是使用第三方库
StaticDataTableViewController 2.0 (https://github.com/xelvenone/StaticDataTableViewController)。
否则,您必须使用有点笨拙的方法将行高更改为 0。
您需要在显示之前隐藏单元格,在 UITableViewDelegate 的 tableView:willDisplayCell:forRowAtIndexPath:
方法中。这是您的控件中可以操作单元格显示的最后一个方法。它不会删除单元格占用的 space,因此您可以尝试的另一件事是使用相同协议的 tableView:heightForRowAtIndexPath:
方法将单元格行的高度设置为 0。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
if (yourCell) {
return 0;
} else {
return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}
}
您好,我一直在寻找一种方法来删除带有动画的静态单元格,但我还没有找到解决问题的方法。
我也试过:[tableView deleteRowsAtIndexPaths:[self.taskArray objectAtIndex:indexPath.row] withRowAnimation:UITableViewRowAnimationFade];
但没有成功。
由于您的 tableview 是静态的,因此您不能使用 deleteRowsAtIndexPath
。最好的选择可能是将您的数据迁移到表视图的数据源方法中。
如果这不可能,那么this answer ("UITableView set to static cells. Is it possible to hide some of the cells programmatically?")给出最好的方法是使用第三方库
StaticDataTableViewController 2.0 (https://github.com/xelvenone/StaticDataTableViewController)。
否则,您必须使用有点笨拙的方法将行高更改为 0。
您需要在显示之前隐藏单元格,在 UITableViewDelegate 的 tableView:willDisplayCell:forRowAtIndexPath:
方法中。这是您的控件中可以操作单元格显示的最后一个方法。它不会删除单元格占用的 space,因此您可以尝试的另一件事是使用相同协议的 tableView:heightForRowAtIndexPath:
方法将单元格行的高度设置为 0。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
if (yourCell) {
return 0;
} else {
return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}
}