【发布时间】:2017-02-28 13:21:17
【问题描述】:
在 iOS 10 上的时钟应用中,在编辑和默认样式之间切换单元格会带来平滑的动画过渡(如下面的录音所示)
我正在尝试为包含 tableview 的简单应用程序复制此转换,但我不知道如何实现动画转换。
我的编辑样式更改的应用代码如下
ViewController.swift
...
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
//Model array for cell data - omitted population of array for simplicity
var notes = [Note]()
//cell editing style
var cellStyleForEditing: UITableViewCellEditingStyle = .none
//The tableview
@IBOutlet weak var NoteTable: UITableView!
...
@IBAction func enableEdittingBttn(_ sender: AnyObject) {
if(cellStyleForEditing == .none) {
cellStyleForEditing = .delete
self.NoteTable.reloadData()
} else {
cellStyleForEditing = .none
self.NoteTable.reloadData()
}
}
//delegate function sets cell editing style on table load/reload
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
return cellStyleForEditing
}
...
//omitted tableview delegate methods
}
如您所见,我是通过在更改表格的单元格编辑样式后重新加载表格数据来实现单元格样式更改的。
为简单起见,我省略了所有不相关的代码。
【问题讨论】:
标签: swift uitableview swift3 ios10