gpt4 book ai didi

ios - 修改 UITableView 中 didSelectRowAtIndexPath 上的单元格

转载 作者:行者123 更新时间:2023-11-28 18:01:14 25 4
gpt4 key购买 nike

我在 TableView 单元格 view1 和 view2 上有 2 个 View ,我想做的是当我点击一个单元格时我希望隐藏 view1 并显示 view2(在开始时显示 view1 和 view2隐藏),我为 View 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);


}

Storyboard enter image description here

模拟器

enter image description here

最佳答案

代替

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

使用

cell = [tableView cellForRowAtIndexPath:indexPath];

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

关于ios - 修改 UITableView 中 didSelectRowAtIndexPath 上的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24849322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com