【发布时间】:2017-07-21 09:38:38
【问题描述】:
这是我的代码
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
print("editingStyle")
if editingStyle == .delete {
//Doing my task
}
}
每次我向左滑动时,其他单元格都会开始抖动,从而造成非常糟糕的用户体验。 我尝试了一些技巧,例如
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier: kCellReuseCardIdentifier) as? MyCustomTableViewCell {
let frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width - 16, height: 125)
cell.frame = frame
cell.contentView.frame = frame
// Cells get squished when editing mode is enabled. To prevent that from happening , we create a dummy cell
let dummyCell = tableView.dequeueReusableCell(withIdentifier: kDummyCellIdentifier) as! DummySpaceTableViewCell
dummyCell.addSubview(cell.contentView)
dummyCell.clipsToBounds = true
return dummyCell
}
有趣的是,这个 hack 在 iOS 11 测试版中工作。在 iOS 10 中,这会导致单元格抖动问题。请注意,我的 tableView 有 n 部分,每个部分都有 1 行。请帮忙。
【问题讨论】: