objective c - Accessing a variable using string -
i wondering if 1 of me little problem having, if possible. have few global variables called checklista, checklistb, etc. want, if user selects table cell called a, checklista passed on destination controller.
in other words:
global variables: nsarrays -> "checklista", "checklistb", "checklistc", etc.
cells: "a", "b", "c", etc
... on click of cell b...
destinationcontroller.checklist = nsarray named: "checklistb"
hope clear, if have questions feel free ask.
thank in advance!
i believe table view has delegate method implemented:
tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath
you notified whenever cell selected(tapped) user.
you can implement delegate method in way:
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { if( indexpath.row == 0) /// first cell { _selectedchecklist = checklista; } else if( indexpath.row == 1) /// second cell { _selectedchecklist = checklistb; } else if( indexpath.row == 2) /// third cell { _selectedchecklist = checklistc; } }
for prepareforsegue
, pass value destination viewcontroller:
- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { destinationcontroller.checklist = _selectedchecklist; }
Comments
Post a Comment