• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 将 UIView 添加到重用的 UITableViewCell?

[复制链接]
菜鸟教程小白 发表于 2022-12-12 16:08:06 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我拼命想达到以下效果:我有一个表格 View ,我想在其中扩展选择的单元格并显示一些附加信息。我重复使用表格单元格,仅供引用。在过去,我能够在另一个应用程序中实现这样的效果,但这似乎对我根本不起作用。所有对发生这种情况至关重要的方法都被调用,并且行扩展得很好,但是 showExpandedContents 方法中的 additionalInfo 表不会出现!

  • 如果我在单元格的初始化中创建 additionalInfo 表,该表会出现,但是当我然后 尝试加载数据(由此,还有单元格)它只是不会重新加载表格。 但是负责这个 (showExpandedContents) 表的方法肯定是被调用的。
  • 如果我初始化 AND 在单元格的初始化代码中设置表格,一切正常。

所以这里有一些代码给你:

这是单元格设置:

-(UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath{

    static NSString *cellID = @"MyCustomCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];

    if(cell == nil){
        cell = [[MyCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }

    ((MyCustomCell*)cell).data = [arrayToDisplay objectAtIndex:indexPath.row];


    return cell;
}

这里是选择方法:

-(void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath{


    [tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
    //setting the current cell as the expandedRow, so that I can collapse it later
    expandedRow = [tableView cellForRowAtIndexPath:indexPath];
    [((MyCustomCell*)expandedRow) showExpandedContents];
    [tableView beginUpdates];
    [self changeRowHeightAtIndex:indexPath.row height:330];
    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    [tableView endUpdates];



}

这是 MyCustomCell 中的 -showExpandedContents 方法,我想在其中显示附加信息:

-(void)showExpandedContents{

    additionalInfo = [[UITableView alloc] initWithFrame:CGRectMake(0, 80, self.frame.size.width, 250)];
    [additionalInfo loadContent];
    additionalInfo.backgroundColor = UIColorFromRGB(0xf9f9f9, 1.0);
    additionalInfo.layer.zPosition = MAXFLOAT;
    [self.contentView addSubview:additionalInfo];

}



Best Answer-推荐答案


看起来像你的

[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

正在为您提供一个新单元格,与调用 showExpandedContents 的单元格不同。

删除此行应该可以解决问题。

关于ios - 将 UIView 添加到重用的 UITableViewCell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19735893/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap