简体   繁体   English

如何通过滑动实现UIActivityIndi​​cator以删除表视图单元格

[英]How to implement UIActivityIndicator with swipe to delete for Table View Cell

I have a table view with swipe to delete functionality. 我有一个滑动删除功能的表格视图。 As soon as I tap delete I want the activity indicator to start animating for that cell and once the background network call is finished I want to stop animation. 当我点击删除时,我希望活动指示器开始对该单元进行动画处理,一旦后台网络通话结束,我想停止动画播放。

Below is my code. 下面是我的代码。 Activity Indicator doesn't work. 活动指示器不起作用。

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == .delete {

        let r = self.tableView(tableView, cellForRowAt: indexPath)

         let indicator = r.viewWithTag(136) as! UIActivityIndicatorView
        indicator.startAnimating()

        let user = fetchedResultsController.object(at: indexPath) as! SharableUser
        deletee(user: user){

            self.managedObjectContext.performAndWait {

                DispatchQueue.main.sync {
                    indicator.stopAnimating()

                    }
                }

                user.accept = 0
                saveData(inContext: self.managedObjectContext)



            }
        }

    }

}

Replace 更换

let r = self.tableView(tableView, cellForRowAt: indexPath)

with

let r = self.tableView.cellForRow(at: indexPath)!

and it's better to make outlet than using view tags 而且制作插座比使用视图标签更好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM