0
votes

I have a table with several sections and lines in each section.

When selecting, I want each item in the table to have its own view controller. I have a given each identifiers.

The following code always opens the same new view controllers, ignoring my if function to make the segue dependent on which cell the user selects. At the moment I am testing with only two but once it works i will add more.

Does anyone know why this happens?

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    if indexPath == 1 {
        self.performSegueWithIdentifier("Belgium", sender: self)

    }
    else {
    self.performSegueWithIdentifier("France", sender: self)
    }
1

1 Answers

1
votes

The if statement isn't being executed because you are comparing indexPath to 1. This will not happen at any point of time.

Objective-C throws a warning saying incompatible pointer NSIndexPath to int comparisons whereas swift executes silently.

The code should be

if indexPath.row == 1 { // Or it can be indexPath.section == 1
    //Do Something
}