Cell上webview加载自适应高度
来源:互联网 发布:iapp表白源码 编辑:程序博客网 时间:2024/06/15 01:19
Demo下载地址Demo下载
直接上代码吧,简单粗暴
- (void)viewDidLoad { [super viewDidLoad]; [self setUI];}- (void)setUI{ [self loadWeb]; [self loadTable];}- (void)loadWeb{ v_webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 1)]; v_webView.delegate = self; v_webView.scrollView.scrollEnabled = NO; v_webView.scrollView.pagingEnabled = NO; v_webView.scrollView.bounces = NO; v_webView.autoresizingMask = UIViewAutoresizingFlexibleWidth; v_webView.autoresizingMask = UIViewAutoresizingFlexibleHeight; //预先加载url [v_webView loadRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://www.baidu.com/"]]];}- (void)loadTable{ table_data = [[UITableView alloc]initWithFrame:CGRectMake(0,0,kScreenWidth,kScreenHeight) style:UITableViewStyleGrouped]; table_data.delegate = self; table_data.dataSource = self; table_data.separatorStyle = UITableViewCellSeparatorStyleNone; [self.view addSubview:table_data]; [table_data registerClass:[ShowTableCell class] forCellReuseIdentifier:@"ShowTableCell"];}#pragma mark - TableViewDelegate & TableViewDatasource- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 20;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.row == 0){ static NSString *identifier = @"ShowTableCell"; ShowTableCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (!cell){ cell = [[ShowTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; /* 忽略点击效果 */ [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; } NSURLRequest *request = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:@"https://www.baidu.com/"]]; [cell.web_info loadRequest:request]; return cell; }else{ static NSString *identifier = @"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (!cell){ cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } cell.textLabel.text = [NSString stringWithFormat:@"index====%ld",(long)indexPath.row]; return cell; }}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;{ if(indexPath.row == 0){ /* 通过webview代理获取到内容高度后,将内容高度设置为cell的高 */ return v_webView.frame.size.height; }else{ return 40; }}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES];}#pragma mark - UIWebView Delegate Methods- (void)webViewDidFinishLoad:(UIWebView *)webView{ //获取到webview的高度 CGFloat height = [[v_webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue]; v_webView.frame = CGRectMake(v_webView.frame.origin.x,v_webView.frame.origin.y, kScreenWidth, height); [table_data reloadData];}
2 0
- Cell上webview加载自适应高度
- cell中嵌套webview自适应高度
- uitableview cell上加载webview
- iOS storyboard约束加载webView自适应高度
- iOS storyboard约束加载webView自适应高度
- UItableView cell 自适应高度
- iOS Cell高度自适应
- ios cell自适应高度
- iOS8 Cell 高度自适应
- Cell自适应高度
- cell单元格高度自适应
- cell自适应高度
- cell自适应高度
- cell的自适应高度
- cell自适应高度
- Cell自适应高度
- cell高度自适应
- cell高度自适应
- Android调用系统相机和相册
- 微信小程序时代,哪些人能赚到第一桶金
- 主从延时(二)
- 微信小程序,学习资源
- binary-tree-preorder-traversal(先序遍历二叉树)
- Cell上webview加载自适应高度
- 开发者狂喜!微信小程序文档和工具放出
- Linux将tomcat加入开机自启动
- 值返回与引用返回
- Android 继承于PopuWindow的自定义弹出窗体
- [插件精选] 炫酷粒子特效
- Android Studio 快捷键
- 「微信小程序」剖析(二):框架原理 | 在桌面浏览器上运行的
- windows下objective-c环境搭建