我在 UITableViewCell 中有一个 UIButton,它自 iOS4 以来一直正常工作,现在自从 iOS7 更新它不再工作。它基本上是一个空盒子的图像。当用户单击图像 (UIButton) 时,图像变为选中框。我没有使用 XIB。有人有什么建议吗?提前致谢。
(我已经尝试过contentView.userInteractionEnabled = NO;
,[cell bringSubviewToFront:button]
但这没有用)
以下是一些相关代码:
- (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];
}