2013-04-28 64 views
0

我试图将自定义UIButton与图像放在自定义tableview单元格中,以将其用作复选标记,第1次水龙头,隐藏复选标记,并且下一次水龙头将其复位... i '尝试下面的代码“示例代码”来执行此功能,但它不隐藏复选标记,即“自定义UIButton”。 不确定我在这里错过了什么?无法隐藏didSelectRowAtIndexPath中的自定义复选标记

- (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; 
    } 
} 

回答

1

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

试试这个:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
     TableViewCell *customCell = (TableViewCell*)[tableView cellForRowAtIndexPath:indexPath]; 
     customCell.checkMarkButton.hidden = !customCell.checkMarkButton.hidden; 
} 
+0

感谢您的答复球员,我试过的建议,但我得到一个警告“不兼容的指针类型,初始化‘TableViewCell *’类型‘的UITableViewCell’的表现” TableViewCell是一个自定义单元类 – DevCali 2013-04-28 20:01:06

+0

只是做一个演员。我编辑了我的答案 – 2013-04-28 20:35:12

+0

谢谢,得到它的工作! – DevCali 2013-04-28 20:52:42

2

替换此行:TableViewCell *customCell = [[TableViewCell alloc]init];本: TableViewCell *customCell = [tableView cellForRowAtIndexPah:indexPath];。你不必创造一个新的细胞,只是得到一个被挖掘的细胞。