我正在我的一个使用自定义表格视图单元格的表格上实现卷帘删除功能。我面临的问题是,当我点击“删除”按钮时,我看到一个奇怪的转换,而单元格正在被删除。
下面是我在"commitEditingStyle“中的代码,还可以看到我在删除行时捕获的附加屏幕截图。
附言:我已经尝试了所有类型的行移除动画样式,但没有运气。
- (void)tableView:(UITableView *)iTableView commitEditingStyle:(UITableViewCellEditingStyle)iEditingStyle forRowAtIndexPath:(NSIndexPath *)iIndexPath {
if (iEditingStyle == UITableViewCellEditingStyleDelete && iTableView == self.temporaryCartTable) {
if (self.temporaryCartTable.frame.size.height == kMyAppCartTableViewExpandedHeight) {
[self.temporaryCartTable beginUpdates];
[self.temporaryCartTable deleteRowsAtIndexPaths:[NSArray arrayWithObjects: iIndexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
MyAppCartInfo *aMyAppCartInfo = [self cart];
if (([[aMyAppCartInfo.tempProducts allKeys] count] > iIndexPath.row) && [aMyAppCartInfo.tempProducts containsObjectForKey:[[aMyAppCartInfo.tempProducts allKeys] objectAtIndex:iIndexPath.row]]) {
[aMyAppCartInfo.tempProducts removeObjectForKey:[[aMyAppCartInfo.tempProducts allKeys] objectAtIndex:iIndexPath.row]];
}
[self.temporaryCartTable endUpdates];
}
}
}
- (BOOL)tableView:(UITableView *)iTableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return (iTableView == self.temporaryCartTable) ? YES : NO;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)iTableView editingStyleForRowAtIndexPath:(NSIndexPath *)iIndexPath {
return UITableViewCellEditingStyleDelete;
}
- (CGFloat)tableView:(UITableView *)iTableView heightForRowAtIndexPath:(NSIndexPath *)iIndexPath {
if (iTableView == self.temporaryCartTable) {
if (self.isTempCartCell)
return 92.0;
else
return 58.0;
} else {
return 58.0;
}
}

发布于 2013-12-26 06:00:37
将以下方法实现添加到UITableViewDelegate中
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}发布于 2014-03-26 20:45:09
使用[self.temporaryCartTable setRowHeight:xxx]而不是使用委派rowHeightAtIndexPath。在删除行并且表中没有其他行之后,委托将不会被调用,您的表视图的行高将由其属性检索(因此为默认高度)。另外,从委托中使用此方法会影响性能。
发布于 2017-12-06 16:07:11
如果其他人也有这种情况,在我的例子中的问题是heightForRowAtIndexPath:,当单元格有动态大小删除动画行为奇怪。在我的案例中,解决方案是使用不同的方法,而不是花费时间进行调查。但您可以对其进行测试并查看结果。为单元格指定固定高度:
self.tableView.rowHeight = Constant;注释掉heightForRowAtIndexPath:。动画现在应该没问题了。
我知道这不是解决方案,但仍然可以帮助别人。
https://stackoverflow.com/questions/20777056
复制相似问题