0

我试图在自定义表格视图单元格上放置一个带有图像的自定义 UIButton 以将其用作复选标记,第一次点击,隐藏复选标记,下一次点击将其带回来......我正在尝试下面的代码“示例代码”来执行这个功能,但它没有隐藏复选标记,即“自定义 UIButton”。不知道我在这里错过了什么?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath    *)indexPath
{
   NSLog(@"%@",indexPath);

    TableViewCell *customCell = [[TableViewCell alloc]init];
    if (customCell.checkMarkButton.hidden == NO) {
    customCell.checkMarkButton.hidden = YES;
    } else {
    customCell.checkMarkButton.hidden = NO;
    }
}
4

2 回答 2

2

将此行: 替换TableViewCell *customCell = [[TableViewCell alloc]init];为 this: TableViewCell *customCell = [tableView cellForRowAtIndexPah:indexPath];。您不必创建新的单元格,只需获取已点击的单元格即可。

于 2013-04-28T18:58:53.433 回答
1

问题是在 didSelectRowAtIndexPath 中,您分配了一个新单元格。

尝试这个 :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath    *)indexPath {
      TableViewCell *customCell = (TableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
      customCell.checkMarkButton.hidden = !customCell.checkMarkButton.hidden;
}
于 2013-04-28T19:02:16.833 回答