Some points still not clear.
- So you have the checkbox (one now, several tomorrow) to control what needs to be displayed. I call them Type 1
So, what are the 2 IBActions ? Referring to which buttons ?
- You say you have checkboxes in front of each propositions
What do you control with those checkboxes ? (I call them type 2)
Are they already used ?
Anyway, I would change your code, to prepare for the future
- create an IBOutlet collection to all the checkbox of Type 1
@IBOutlet var checkBoxes: [UIButton]!
- connect to the appropriate checkboxes
- define a tag from 0 to N-1 for the checkboxes N = number of checkboxes
Use the same IBAction for all checkboxes
If you need to know which checkbox, test the tag
@IBOutlet var checkBoxes: [UIButton]!
@IBOutlet weak var tblView: UITableView!
let fruitsNamesArray = ["Abricot", "Ananas", "Avocat", "Brugnon", "Cacahuète", "Cassis", "Cerise", "Châtaigne", "Citron", "Citron Vert", "Clémentine", "Coing", "Datte", "Figue", "Fraise", "Framboise", "Fruit de la passion", "Grenande", "Groseille", "Kiwi", "Litchi", "Mandarine", "Mangue", "Marron", "Melon", "Mirabelle", "Mûre", "Myrtille", "Nectarine", "Noisette", "Noix"]
let recipes = ["Tarte Tatin", "Tarte aux pommes", "Biscuit roulé"]
// Checkbox
@IBAction func checkBoxTapped(_ sender: UIButton) {
sender.isSelected = !sender.isSelected
switch sender.tag {
case 0 : // depending on checvkBoxes[0] selected, show or hide some information (index) by setting infosToDisplay[index]
infosToDisplay[0] = true // just to illustrate : show "Tarte Tatin"
infosToDisplay[0] = false // just to illustrate : hide "Tarte aux pommes"
infosToDisplay[0] = true // just to illustrate : show "Biscuit roulé"
default: break
}
}
But, you do not explain
- how is information defined
I assume you have an Array
recipes = ["Tarte Tatin", "Tarte aux pommes", "Biscuit roulé"]
- how you select to show/hide some information depending on check
SO, PLEASE, show the complete code of the class
It is likely that you should define some data structures, as dictionaries, such as
var ingredients : [String: [String]]
ingredients["Tarte Tatin"] = ["Pomme"] // Celui là manque …
ingredients["Biscuit Roulé"] = ["Marron", "Groseille"]
Final note: in IOS App, usually you use switch instead of checkboxes. But it is up to you.