【问题标题】:UITableView insertRowsAtIndexPaths remove cell separatorUITableView insertRowsAtIndexPaths 删除单元格分隔符
【发布时间】:2014-06-11 10:59:30
【问题描述】:

我需要在所选行下添加一个新行。我在 didSelectRowAtIndexPath 中使用此代码:

[_dataSource insertObject:newDataObject atIndex:indexPath.row + 1];

NSMutableArray *indexPaths = [NSMutableArray array];
NSInteger currentCount = indexPath.row;
[indexPaths addObject:[NSIndexPath indexPathForRow:currentCount+1 inSection:0]];

[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];

它会在正确的位置添加新行,但也会删除所选行的上部单元格分隔符。我做错了什么?

【问题讨论】:

  • 会不会是你的新单元格高度不对?
  • 不,因为当我在 cellForRowAtIndexPath 中创建单元格时,我总是使用相同的高度。而且内容也是一样的。
  • 我曾经问过我有一个问题,一旦我改变了原型单元格的数量并且调整了单元格的大小:) 并且相互重叠
  • 如果您通过界面构建​​器使用隐式高度,请覆盖委托方法并指定要测试的恒定高度。
  • 我在 cellForRowAtIndexPath 中指定了行高(它是常数)。

标签: ios objective-c uitableview didselectrowatindexpath


【解决方案1】:

似乎 UITableViewCell 在选定状态下没有分隔符。 UITableViewCellSelectionStyleNone 只是禁用突出显示,但单元格是selected 无论如何。添加

   [tableView beginUpdates];
   // insert/delete manipulations
   [tableView deselectRowAtIndexPath:indexPath animated:NO];
   [tableView endUpdates];

解决问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-05
    • 2021-06-02
    • 2011-02-09
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    相关资源
    最近更新 更多