iOS UITableView 自定义cell中嵌套webview自适应高度

本文介绍了如何在iOS应用中,为UITableView的自定义cell内嵌入WebView并实现内容自适应高度。通过监听WebView加载完成的通知,动态更新cell高度,确保内容完整显示。同时,对网页样式进行了设置,以适应不同设备的屏幕尺寸。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

-(void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    self.heightDic = [[NSMutableDictionary alloc]init];

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(notifi:) name:@"TestHeight" object:nil];

}

 

-(void)notifi:(NSNotification *)nofi

{

    TestCell * cell = nofi.userInfo[@"DataView"];

    NSIndexPath * indexPath = [self.tableView indexPathForCell:cell];

    if (![self.heightDic objectForKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]]) {

        [self.heightDic setObject:nofi.userInfo[@"DataHeight"] forKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]];

        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableV

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值