我在表视图单元格view1和view2上有2个视图,我想要做的是当我点击一个单元格时我希望隐藏view1并显示view2(在开始时显示view1并且view2是隐藏),我使用标签查看view1 = 102和view2 = 103,由于某种原因我无法想象,view1被隐藏但view2没有显示。
这是我的代码:
- (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);
}
故事板
模拟器
答案 0 :(得分:8)
而不是
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
使用
cell = [tableView cellForRowAtIndexPath:indexPath];
因为dequeueReusableCellWithIdentifier: forIndexPath:
将返回当前不可见的当前未使用的表格单元格。