Reload section method in swift 3?

后端 未结 3 1441
有刺的猬
有刺的猬 2020-12-15 04:31

I have code written in objective c.I want to convert this code into the swift3 code.

[_expandableTableView reloadSections:[NSIndexSet indexSetWithIndex:gestu         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-15 04:59

    Note that after the conversion NSIndexSet became IndexSet. IndexSet is the Swift overlay to the Foundation framework for 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.

    If you checked the description of reloadSections method signature, you will note that it is:

    reloadSections(_ sections: IndexSet, with animation: UITableViewRowAnimation

    sections parameter is IndexSet but NOT NSIndexSet anymore.

    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:

    _expandableTableView.reloadSections(IndexSet(integer: gestureRecognizer.view!.tag), with: .automatic)
    

提交回复
热议问题