我正在尝试在我的 tableviewCells 中创建一个星形按钮,以便用户可以保存最喜欢的项目。
到目前为止,我已经尝试过了。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
UIButton *CameraBreak=[UIButton buttonWithType:UIButtonTypeRoundedRect];
CameraBreak.frame=CGRectMake(260, 10, 60, 40);
CameraBreak.tag=indexPath.row;
[CameraBreak setImage:[UIImage imageNamed:@"first.png"] forState:UIControlStateNormal];
[CameraBreak addTarget:self action:@selector(starClicked::) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:CameraBreak];
cell.textLabel.text = [titles objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15];
return cell;
}
问题是 viewDidLoad 上的按钮如下所示:
但是,一旦我浏览表格,它的按钮就会改变如下:
有人知道这种行为的原因吗?我该如何解决这个问题?
更新
未选中的:
已选择: