Hi Julian,
Thanks a lot for the interesting question. The way I'd approach this is that I'd create everything normally, then when the button is tapped, I'd loop through all the cells in the section and set their control's "enabled" property to FALSE. Here is a code sample illustrating this:
- (void)tableViewModel:(SCTableViewModel *)tableViewModel
detailViewWillAppearForRowAtIndexPath:(NSIndexPath *)indexPath
withDetailTableViewModel:(SCTableViewModel *)detailTableViewModel
{
// objectSection is just a variable to hold the object section
self.objectSection = [detailTableViewModel sectionAtIndex:0];
[self setEnabledStateForSection:self.objectSection state:FALSE];
// You can add the toggle button to the detail navigation bar here
UIBarButtonItem *button = [[UIBarButtonItem alloc]
initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self
action:@selector(buttonTapped)];
detailTableViewModel.viewController.navigationItem.rightBarButtonItem = button;
[button release];
}
- (void)buttonTapped
{
// controlState is just a variable used to toggle the control states
self.controlState = !self.controlState;
[self setEnabledStateForSection:self.objectSection
state:self.controlState];
}
- (void)setEnabledStateForSection:(SCTableViewSection *)section
state:(BOOL)state
{
for(int i=0; i<section.cellCount; i++)
{
SCTableViewCell *cell = [section cellAtIndex:i];
if([cell isKindOfClass:[SCControlCell class]])
{
SCControlCell *controlCell = (SCControlCell *)cell;
if([controlCell.control isKindOfClass:[UIControl class]])
{
((UIControl *)controlCell.control).enabled = state;
}
else if([controlCell.control isKindOfClass:[UITextView class]])
{
((UITextView *)controlCell.control).editable = state;
}
}
}
}