1

I have a table view with a number of rows depending on how many entries the user created. Lets assume the user created 2 entries thus we have 2 rows.

Now Each row when tapped creates a subview with another table with 2 rows and 2 UISwitches (Just like a tree. 2 rows, each expanding to 2 new rows each with a UISwitch)

All UISwitch states when changed update a Dictionary of Dictionaries. e.g. the following

[0: [0: false, 1: true], 1: [0: false, 1: false]]

row 0 -> first switch: OFF, Second:ON

row 1 -> first switch: OFF, Second:OFF

Scenario :

All UISwitches are ON thus, [0: [0: true, 1: true], 1: [0: true, 1: true]]

First UISwitch of 0th row tapped off-> [0: [0: false, 1: true], 1: [0: true, 1: true]]

Second UISwitch of 1st row tapped off -> [0: [0: false, 1: true], 1: [0: false, 1: false]]

It turns eachself Off as intended, but also all other (bolded) that where tapped OFF in step one for a different row of UIswitches. It seems that it remembers the previous step but messes up the rows.

Code:

//smallDictionary is a dictionary
//bigDictionary is a dictionary of dictionaries
// smallDictionary is appended to bigDictionary
// row is a variable updated everytime some row is tapped. 

@IBAction func switchChanged(sender: UISwitch) {
    if sender.on == true {
        smallDictionary[sender.tag]! = true  
        bigDictionary[row]! = globalswitchSaveDict

    }
    else  {
        smallDictionary[sender.tag]! = false
        bigDictionary[row]! = globalswitchSaveDict
    }
}
Tromos
  • 89
  • 6

1 Answers1

0

Fixed the issue.

Had to add aline of code to update the correct smallDict as shown:

@IBAction func switchChanged(sender: UISwitch) {
    smallDictionary = bigDictionary[row]!
    if sender.on == true {
        smallDictionary[sender.tag]! = true  
        bigDictionary[row]! = globalswitchSaveDict

    }
    else  {
        smallDictionary[sender.tag]! = false
        bigDictionary[row]! = globalswitchSaveDict
    }
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Tromos
  • 89
  • 6