Search code examples
iphoneuitableviewcustom-action

iphone: changing status of several segment controllers at once in custom cell


I have a tableView with the custom cell (see image below.)

Taking a three row table as an example, if a user changes segment controller in row 0 to "Yes," can I automatically change the segment controllers in rows 1 & 2 to "No?"

I am using the following to detect a segment change:

- (void)seg_changed:(id) sender {

cell=(switchCell*) [[sender superview] superview];

UITableView *table=(UITableView*) [cell superview];

NSIndexPath *path=[table indexPathForCell:cell];

NSLog(@"been pressed %d si %d",path.section, path.row);

}

Much appreciated.

enter image description here


Solution

  • In this method you call just tell those other segment controllers to set their values to "NO". The hard part is figuring out where those two other controls are. You have to do the hard work of tracking them.

    If your design ensures there are always two more cell with segmented controls you can just access the correct cells by incrementing the path.row value.

    This change can tell your data model that a value has changed, the model object then updates the associated values, and notifies the cells displaying those other values.

    You can add an array to this cell class that keeps track of what other cells should be modified with this change.

    Edit: (to respond to a comment) To change the setting displayed on the segmented control just set the property selectedSegmentIndex of the UISegmentedControl to the appropriate value. "Yes" should be 0, and "No" should be 1.