2014-07-20 94 views
0

我对表格视图单元格view1和view2有2个视图,我想要做的是当我点击一个单元格时,我希望view1被隐藏并且view2被显示(在开始view1被显示,view2被隐藏),我用视图view1 = 102和view2 = 103的标签,出于某种原因,我无法确定,view1被隐藏,但view2不被显示。修改UITableView中didSelectRowAtIndexPath上的单元格

这里是我的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 


    UIView * view1 = (UIView *)[cell viewWithTag:102]; 
    UIView * view2 = (UIView *)[cell viewWithTag:103]; 

    [view1 setHidden:YES]; 
    [view2 setHidden:NO]; 


    NSLog(@"View 2 is : %hhd",view2.hidden); 


} 

故事板 enter image description here

模拟器

enter image description here

回答

6

,而不是

cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 

使用

cell = [tableView cellForRowAtIndexPath:indexPath]; 

因为dequeueReusableCellWithIdentifier: forIndexPath:将返回当前不可见当前未使用的表格单元格。

相关问题