ios 在swift 3中重新加载部分方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40376728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reload section method in swift 3?
提问by TechChain
I have code written in objective c.I want to convert this code into the swift3 code.
我有用客观 c 编写的代码我想将此代码转换为 swift3 代码。
[_expandableTableView reloadSections:[NSIndexSet indexSetWithIndex:gestureRecognizer.view.tag] withRowAnimation:UITableViewRowAnimationAutomatic];
After converting using online tool it gave me below code but it does not work
使用在线工具转换后,它给了我下面的代码,但它不起作用
expandableTableView.reloadSections(IndexSet(index: gestureRecognizer.view!.tag), with: .automatic)
Please tell me how to do it ?
请告诉我怎么做?
回答by Mohamed Jaleel Nazir
Reload Section in Swift 3.0
在Swift 3.0 中重新加载部分
i.e Reloading 0th section to 0th Section, Because tableview has defaultly one section that index is 0.
即重新加载第 0 节到第 0 节,因为 tableview 默认有一个索引为 0 的节。
//let myRange: ClosedRange = 0...0
self.tableViewPostComments.reloadSections(IndexSet(integersIn: 0...0), with: UITableViewRowAnimation.top)
For Swift 4
对于 Swift 4
self.tableViewPostComments.reloadSections(IndexSet(integersIn: 0...0), with: UITableView.RowAnimation.top)
回答by Dung Tran
回答by Ahmad F
Note that after the conversion NSIndexSet
became IndexSet
. IndexSetis the Swift overlay to the Foundation framework for NSIndexSet:
注意转换后NSIndexSet
变成了IndexSet
. 索引集是斯威夫特覆盖为基础框架的NSIndexSet:
The Swift overlay to the Foundation framework provides the IndexSet structure, which bridges to the NSIndexSet class and its mutable subclass, NSMutableIndexSet. The IndexSet value type offers the same functionality as the NSIndexSet reference type, and the two can be used interchangeably in Swift code that interacts with Objective-C APIs. This behavior is similar to how Swift bridges standard string, numeric, and collection types to their corresponding Foundation classes.
Swift 覆盖到 Foundation 框架提供了 IndexSet 结构,它连接到 NSIndexSet 类及其可变子类 NSMutableIndexSet。IndexSet 值类型提供与 NSIndexSet 引用类型相同的功能,并且两者可以在与 Objective-C API 交互的 Swift 代码中互换使用。这种行为类似于 Swift 将标准字符串、数字和集合类型桥接到它们相应的 Foundation 类的方式。
If you checked the description of reloadSections
method signature, you will note that it is:
如果你检查了reloadSections
方法签名的描述,你会注意到它是:
reloadSections(_ sections: IndexSet, with animation: UITableViewRowAnimation
reloadSections(_部分:IndexSet,带动画:UITableViewRowAnimation
sections
parameter is IndexSet
but NOT NSIndexSet
anymore.
sections
参数是IndexSet
但不是NSIndexSet
了。
So, what you could do is:
所以,你可以做的是:
_expandableTableView.reloadSections(NSIndexSet(index: gestureRecognizer.view.tag) as IndexSet, with: .automatic)
OR I prefer to add IndexSet without even using the as IndexSet
:
或者我更喜欢添加 IndexSet 甚至不使用as IndexSet
:
_expandableTableView.reloadSections(IndexSet(integer: gestureRecognizer.view!.tag), with: .automatic)