selectrow at index for different sections

161 views Asked by At

I have a table with two sections. I can select row at index - but I cannot differentiate between the sections.

the table is a pullout menu - which is created solely in code.

the delegate method for the selection is

func sideBarControlDidSelectRow(indexPath: NSIndexPath) {
    delegate?.sideBarDidSelectButtonAtIndex(indexPath.row)
    sectionis = indexPath.section
    NSLog("Index Path Section %d", indexPath.section)
}

this gives me the section in the console.

but on the view controller all I have is

func sideBarDidSelectButtonAtIndex(index: Int){
    switch(index) {
        etc.
    }
}

What I need to be able to do is something like

func sideBarDidSelectButtonAtIndex(index: Int){
    if section == 0 {
        switch(index){
            etc.
        }
    }
}

but if I try that then Binary operator cannot be applied to operands of type section

this has got to be something obvious as tables have sections all the time - but the answer is eluding me.

1

There are 1 answers

1
Alex Antonyuk On BEST ANSWER

Just update declaration of method sideBarDidSelectButtonAtIndex in delegate protocol to accept NSIndexPath value, change:

func sideBarDidSelectButtonAtIndex(index: Int)

to

func sideBarDidSelectButtonAtIndex(indexPath: NSIndexPath)

then you can just remove this method

func sideBarControlDidSelectRow(indexPath: NSIndexPath) {
    delegate?.sideBarDidSelectButtonAtIndex(indexPath.row)
}

and replace its call just with

delegate?.sideBarDidSelectButtonAtIndex(indexPath)

Then you'll receive full indexPath and could do what you want