How to access the value of an NSIndexPath section?

I do not understand why in the following code indexPath.sectionreconfigures a null value.

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell? {
    NSLog("Index Path %@", indexPath)
    // Index Path <NSIndexPath: 0x1666d1d0> {length = 2, path = 0 - 0}

    NSLog("Index Path Section %@", indexPath.section)
    // Index Path Section (null)

Following this question, I also tried the following to access the value of the section:

if let section = indexPath?.section {
    NSLog("Index Path Section %@", section)
}

I have a table with 2 sections with 1 row in each section. At the first iteration, where path = 0 - 0, the log shows Index Path Section (null). At the second iteration, where the path = 1 - 0program will work.

I'm not trying to do something complicated, I just need to access the value of the section so that I can conditionally return the correct cell type.

+4
source share
1 answer

. .

section NSInteger, Int swift

NSLog("Index Path Section %d", indexPath.section)

(null), 0. , 1,

+6

Source: https://habr.com/ru/post/1544086/


All Articles