-1

I have a ListTableView with cells organized in several sections. Another FilterTableView (filter settings for the ListTableView) provided by another controller. Every cell of FilterTableView has a UISwitch to set the showing/hiding state of a specified section of ListTableView.

How exactly do I save the BOOL state of UISwitch?

What kind of model do I need to provide?

What is the right way to pass the state of UISwitch of cells of FilterTableView to show/hide sections in ListTableView?

Thanks for your help in advance!

Rumin
  • 3,787
  • 3
  • 27
  • 30
eli7ah
  • 355
  • 2
  • 10

2 Answers2

0

You need to either pass a reference to the item in your data source to the cell so it can change it directly (for example, pass in a Filter object), or you need to make the FilterTableView a delegate of each cell and have the cell notify its delegate when the switch value changes.

If the cell is generic and you also use it in other places for other things, go with the delegate pattern. But if it's unique to this table view, it's probably easier just to pass it the Filter object. That way it can also set its label and switch state itself, rather than requiring the data source to set its values.

Dave Batton
  • 8,795
  • 1
  • 46
  • 50
0

If you are using a stroyboard you can create an unwind segue (to go back from FilterTableViewCtrl to ListTableViewCtrl). This case you can save data in the unwind action method which is located in ListTableViewCtrl.

- (IBAction)unwindToList:(UIStoryboardSegue*)unwindSegue
{
    UIViewController* sourceViewController = unwindSegue.sourceViewController;
    if ([sourceViewController isKindOfClass:[FilterTableViewCtrl class]])
    {
        FilterTableViewCtrl* filter = (FilterTableViewCtrl*)unwindSegue.sourceViewController;
        //read state of filter, and update list (self)
    }
}

More details in: View Controller Programming Guide for iOS / Creating an Unwind Segue

fabe
  • 718
  • 5
  • 10