I have a UIButton in a UITableViewCell that has been working correctly since iOS4, now since the iOS7 update it no longer works. It is basically an image of an empty box. When user clicks on the image (UIButton) the image changes to a checked box. I am NOT using an XIB. Anybody have any suggestions? Thanks in advance.
(I have already tried contentView.userInteractionEnabled = NO;
and [cell bringSubviewToFront:button]
but this didn't work)
Here is some relevant code:
- (UITableViewCell *)taskCell:(NSIndexPath *)indexPath table:(UITableView *)localTableView managed:(NSManagedObject *)managedTask dateFormat:(NSDateFormatter *)localDateFormatter{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [localTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
// Checkbox
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(-4.0f, -3.0f, 48.0f, 48.0f)];
button.tag=kCellButtonViewTag;
button.adjustsImageWhenHighlighted=NO;
[button setImage:[UIImage imageNamed:@"uncheckedPriorityNone.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(toggleCheckedMode:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button];
[button release];
}
}
- (IBAction)toggleCheckedMode:(id)sender{
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
UITableViewCell *clickedCell = (UITableViewCell *)[[sender superview] superview];
NSIndexPath *indexPath = [self.tableView indexPathForCell:clickedCell];
Task *localTask = [self.fetchedResultsController objectAtIndexPath:indexPath];
UIButton *button = sender;
[button setImage:[UIImage imageNamed:@"checkedGray.png"] forState:UIControlStateNormal];
}
Try adding the view to the cell itself, not to the contentView.
So
[cell addSubview:button];
Instead of
[cell.contentView addSubview:button];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With