简体   繁体   English

UITableView滑动操作可删除并使用自定义视图进行编辑

[英]UITableView swipe action delete and edit with custom view

I am setting view when swipe tableview cell like as 1st view in table it need to be stick on as second view and change its color. 我正在设置视图,当像在表中的第一个视图一样滑动tableview单元格时,它需要坚持作为第二个视图并更改其颜色。

Is it possible in Swift 4 and iOS? 在Swift 4和iOS中可以吗?

在此处输入图片说明

Once you are getting the swipe gesture in view controller you do the next: 在View Controller中获得滑动手势后,请执行以下操作:

func didSwipe(_ cell: UITableViewCell) {
   let indexPath = tableView.indexPath(for: cell)
   if indexPath.row + 1 < myViewModels.count - 1 {
     // Store the info from the next view model to the current one
     myViewModels[indexPath.row].update(with: myViewModels[indexPath.row + 1])
     tableView.reloadItems(at: [indexPath])
   }
}

myViewModels is an array of object(contains data, colors, etc) that you are displaying Instead of update you can manually update necessary fields myViewModels是要显示的对象数组(包含数据,颜色等),而不是更新,您可以手动更新必要的字段

The code may have an errors but the idea should be clear 代码可能有错误,但是思路应该清晰

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

相关问题 通过尝试删除,对UITableViewCell的自定义编辑操作在滑动时崩溃 - Custom edit action on UITableViewCell crashes on swipe by trying to delete 是否无法在 UITableViewCell 上的删除操作(滑动按钮)中使用自定义视图? - Is it impossible to use custom view in delete action ( swipe button ) on UITableViewCell? 为 UITableView 滑动操作设置自定义字体 (UIContextualAction) - Set custom font for UITableView swipe action (UIContextualAction) UITableView禁用滑动以删除,但在编辑模式下仍具有删除功能? - UITableView disable swipe to delete, but still have delete in Edit mode? 允许UITableView重新排序,但不能在编辑模式下删除,并启用滑动以删除 - Allow UITableView to reorder, but not delete in edit mode, and enable swipe to delete anyway 可以编辑滑动以删除(在UITableView中)默认文本或翻译它吗? - It is possible to edit swipe to delete's (in UITableView) default text or translate it? 滑动UITableView进行编辑 - UITableView swipe to edit UITableView中的自定义单元格在滑动后立即进行编辑 - Custom cell in UITableView shifts right after swipe to edit 滑动即可删除UITableView - Swipe to delete UITableView 是否可以在UITableView编辑模式下更改默认删除操作图标? - Is it possible to change default delete action Icon in UITableView edit mode?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM