在swift 3中重新加载部分方法?
我有目标cI编写的代码想要将此代码转换为swift3代码。
[_expandableTableView reloadSections:[NSIndexSet indexSetWithIndex:gestureRecognizer.view.tag] withRowAnimation:UITableViewRowAnimationAutomatic];
使用在线工具转换后,它给了我下面的代码,但它不起作用
expandableTableView.reloadSections(IndexSet(index: gestureRecognizer.view!.tag), with: .automatic)
请告诉我怎么做?
喜欢在swift3中获取更多信息,请参阅此内容
expandableTableView.reloadSections(IndexSet(integer: gestureRecognizer.view!.tag), with: .automatic)
在Swift 3.0中重新加载部分
即将第0部分重新加载到第0部分,因为tableview默认有一个索引为0的部分。
//let myRange: ClosedRange = 0...0 self.tableViewPostComments.reloadSections(IndexSet(integersIn: 0...0), with: UITableViewRowAnimation.top)
请注意,转换后NSIndexSet
成为IndexSet
。 IndexSet是NSIndexSet的Foundation框架的Swift叠加:
基础框架的Swift覆盖提供了IndexSet结构,该结构桥接到NSIndexSet类及其可变子类NSMutableIndexSet。 IndexSet值类型提供与NSIndexSet引用类型相同的function,并且这两者可以在与Objective-C API交互的Swift代码中互换使用。 此行为类似于Swift如何将标准字符串,数字和集合类型桥接到其对应的Foundation类。
如果您检查了reloadSections
方法签名的描述,您将注意到它是:
reloadSections(_ sections:IndexSet,带动画:UITableViewRowAnimation
sections
参数是IndexSet
但不再是IndexSet
。
所以,你能做的是:
_expandableTableView.reloadSections(NSIndexSet(index: gestureRecognizer.view.tag) as IndexSet, with: .automatic)
或者我更喜欢在不使用as IndexSet
情况下添加as IndexSet
:
_expandableTableView.reloadSections(IndexSet(integer: gestureRecognizer.view!.tag), with: .automatic)