Q:

Table with multiple sections depending on toggle

I am creating a tableview that is being populated with values from a plist. 
I also have a favorites section in the table that will be populated from the same plist depending is a boolean value in the plist is true or false. 
The problem I'm having is whenever the tableview gets refreshed the cell changes to a different value in an array.
Here is my cell code:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    //Define cell in view controller
    let cell = tableView.dequeueReusableCellWithIdentifier("tableCell", forIndexPath: indexPath) as UITableViewCell

    //Get information from routeArrayionary
    if let inforouteArray = self.routeArray![indexPath.row] as? NSDictionary,
        let nameString = inforouteArray["name"], let nameCode = inforouteArray["code"], let isFav = inforouteArray["isFavorite"] {
        if (indexPath.section == 0) {
            if (isFav as! Bool == true) {
                cell.textLabel?.text = "\(nameString) (\(nameCode))"
            }
        } else {
            cell.textLabel?.text = "\(nameString) (\(nameCode))"

        }
    }
    return cell

}

Move row:
if (sourceIndexPath != destinationIndexPath) {
    if (destinationIndexPath.section == 0) {
        self.routeArray![sourceIndexPath.row].setValue(true, forKey: "isFavorite")
    } else {
        self.routeArray![sourceIndexPath.row].setValue(false, forKey: "isFavorite")

    }
    if(self.routeArray!.writeToFile(self.path!, atomically: true) == true) {
        NSLog("Successfully saved favorites")
    }

    self.tableView.reloadData()
}

and how I'm calculating the number of rows in a section:
if (section == 0) {
    var i: Int = 0
    for route in routeArray! {
        if (route["isFavorite"] as! Bool == true) {
            i += 1
        }
    }

    return i

} else {
    return numRows!
}

RouteArray stucture:
{
    code = **;
    color = 0000FF;
    isFavorite = 0;
    name = “**”;
    routeId = 55;
    weight = 0;
},
{
    code = **;
    color = DDDDDD;
    isFavorite = 0;
    name = “**”;
    routeId = 57;
    weight = 1;
}

I'm really not too sure where to go from here.

A:

Basically, in the favorites section, your indexing is wrong. Let's say you've added item 0, 5, and 7 to the favorites section. iOS will call cellForRowAtIndexPath with indexPath.section == 0 and indexPath.row = 0, 1, 2. You would need to map 0, 1, 2 to 0, 5, 7 - which you don't do. "if (isFav as! Bool == true)" will not be true for the rows 1 and 2, there is no else branch, so you leave the cell text unset. Since the cell is reused, the cell text just stays whatever it was from the previous use.
Probably the best you can do is to create a second array "favoriteRouteArray" which is filtered to the favorite entries, and use this for the favorites section.

