How to create NSIndexPath for TableView

后端 未结 4 466
臣服心动
臣服心动 2021-01-29 18:39

I need delete row 1 of a table in a function I have defined. In order to use deleteRowAtIndexPath you must use an IndexPath with a section and row defi

相关标签:
4条回答
  • 2021-01-29 18:56

    Use [NSIndexPath indexPathForRow:inSection:] to quickly create an index path.

    Edit: In Swift 3:

    let indexPath = IndexPath(row: rowIndex, section: sectionIndex)
    

    Swift 5

    IndexPath(row: 0, section: 0)
    
    0 讨论(0)
  • 2021-01-29 19:02

    For Swift 3 it's now: IndexPath(row: rowIndex, section: sectionIndex)

    0 讨论(0)
  • 2021-01-29 19:05

    indexPathForRow is a class method!

    The code should read:

    NSIndexPath *myIP = [NSIndexPath indexPathForRow:0 inSection:0] ;
    
    0 讨论(0)
  • 2021-01-29 19:11

    Obligatory answer in Swift : NSIndexPath(forRow:row, inSection: section)

    You will notice that NSIndexPath.indexPathForRow(row, inSection: section) is not available in swift and you must use the first method to construct the indexPath.

    0 讨论(0)
提交回复
热议问题