swift tableview中添加侧滑删除功能 类似qq删除
2015-05-07 11:01
495 查看
在UITableViewDelegate 中继承三个方法
func tableView(tableView:UITableView, canEditRowAtIndexPath indexPath:
NSIndexPath) -> Bool
func tableView(tableView:UITableView, editingStyleForRowAtIndexPath indexPath:NSIndexPath)
-> UITableViewCellEditingStyle
func tableView(tableView:UITableView, commitEditingStyle editingStyle:
UITableViewCellEditingStyle, forRowAtIndexPath indexPath:
NSIndexPath)
然后分别在三分方法中添加业务逻辑。
func tableView(tableView:UITableView, canEditRowAtIndexPath indexPath:
NSIndexPath) -> Bool
func tableView(tableView:UITableView, editingStyleForRowAtIndexPath indexPath:NSIndexPath)
-> UITableViewCellEditingStyle
func tableView(tableView:UITableView, commitEditingStyle editingStyle:
UITableViewCellEditingStyle, forRowAtIndexPath indexPath:
NSIndexPath)
然后分别在三分方法中添加业务逻辑。
<pre name="code" class="objc"><pre name="code" class="plain">//mark 设置可以进行编辑 func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool{ println("mark 设置可以进行编辑")
return true } // mark 设置编辑的样式 func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle{ println("mark 设置编辑的样式") return UITableViewCellEditingStyle.Delete } //删除cell func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath){ println("删除cell") if editingStyle == UITableViewCellEditingStyle.Delete{ //1,从本地数据库将数据移除
//调用dbhelper中的delete方法删除cocodata中的数据 dbhelper.deleteConversationBySay(conlist[indexPath.row].say) conlist.removeAtIndex(indexPath.row) //2.reload
//直接使用reload方法界面的变化非常迅速,用户体验非常不好 //tv.reloadData() //这个具有动画效果 self.tv.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic) } }
相关文章推荐
- Swift - 动态添加删除TableView的单元格(以及内部元件)
- Swift - tableView的单元格多选功能的实现(获取多选值、多选删除)
- tableView上的侧滑删除功能
- iOS实现类似QQ的好友列表,自由展开折叠(在原来TableView的基础上添加一个字典,一个Button)
- 实现类似QQ聊天列表的segment点击切换tableView的数据功能
- Swift - 动态添加删除TableView的单元格(以及内部元件-日期控件)
- ios tableView 的cell打开收起功能,类似QQ中的cell折叠功能
- 使用RecylerView完成拖动排序高仿qq侧滑删除功能
- UITableView实现类似QQ好友的折叠功能
- ios tableview cell 侧滑删除
- Snail—UI学习之表视图TableView单行添加、删除和移动
- Android一步一步带你实现RecyclerView的拖拽和侧滑删除功能
- ios TableView那些事(三十一)UITableViewController ios8 删除时添加多个按钮
- Android自定义View之自定义EditText(添加删除功能)
- TableView中表格的添加与删除
- swift-tableView 删除行
- 95.UICollectionView添加headerView(类似UITableView的tableHeaderView)
- (原创)iOS tableview系统左滑删除 左滑置顶 自定义左滑事件功能 输入框弹出
- Swift - 给表格TableView添加页眉和页脚
- JS小功能(操作Table--动态添加删除表格及数据)实现代码