The tableview is populated from a .plist.
I want to be create an “ADD” button on the navBar if one or more cells are checked and remove the “ADD” button once all of the cells are unchecked. The best I’ve been able to do is add the button when a cell is checked and remove the button when the cell is unchecked but this is not taking into account that other cells may have a checkmark in them. If any cell is in the table has a checkmark, the “ADD” button should be present.
The example code I’m working with can be found here: http://developer.apple.com/library/ios/#samplecode/TouchCells/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008062
In the didSelectRowAtIndexPath method, I’ve added:
if (targetCustomCell.checked)
{
UIBarButtonItem *saveButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Add"
style:UIBarButtonItemStyleDone target:self action:@selector(add)];
self.navigationItem.rightBarButtonItem = saveButtonItem;
}
else
{
self.navigationItem.rightBarButtonItem = nil;
}
I’m including the DidSelectRowAtIndexPath for reference:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// find the cell being touched and update its checked/unchecked image
CustomCell *targetCustomCell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath];
[targetCustomCell checkAction:nil];
// don't keep the table selection
[tableView deselectRowAtIndexPath:indexPath animated:YES];
// update our data source array with the new checked state
NSMutableDictionary *selectedItem = [self.dataArray objectAtIndex:indexPath.row];
[selectedItem setObject:[NSNumber numberWithBool:targetCustomCell.checked] forKey:@"checked"];
}
Thank you for any help – it’s really appreciated!
I guess this is what you want.