【问题标题】:Table View Cells start shaking when trying to swipe to delete current cell尝试滑动删除当前单元格时,表格视图单元格开始抖动
【发布时间】: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 行。请帮忙。

【问题讨论】:

    标签: ios swift tableview


    【解决方案1】:
    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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-20
      • 2016-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多