这是我的代码
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 行。请帮忙。
答案 0 :(得分:0)
I have used MGSwipeTableCell to prevent from above issue.
You can find the code & examples from below link.
https://github.com/MortimerGoro/MGSwipeTableCell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
experienceCell * experienceCell = [tableView dequeueReusableCellWithIdentifier:@"experienceCell"];
MGSwipeButton *DeleteButton=[MGSwipeButton buttonWithTitle:@"" icon:[UIImage imageNamed:@"delete_white"] backgroundColor:THEME_COLOR padding:15];
DeleteButton.titleLabel.font=ROBOTO_REGULAR_FONT16;
experienceCell.rightSwipeSettings.transition=MGSwipeTransitionStatic;
experienceCell.rightExpansion.buttonIndex=0;
experienceCell.rightExpansion.fillOnTrigger=true;
experienceCell.rightButtons=@[DeleteButton];
experienceCell.delegate = self;
experience = true;
return experienceCell;
}
-(BOOL) swipeTableCell:(MGSwipeTableCell*) cell tappedButtonAtIndex:(NSInteger) index direction:(MGSwipeDirection)direction fromExpansion:(BOOL) fromExpansion
{
if(direction == MGSwipeDirectionRightToLeft && index == 0)
{
}
return YES;
}