tabViewCell里面添加webView
来源:互联网 发布:淘宝店卖童装用压货吗 编辑:程序博客网 时间:2024/06/04 18:04
在UItabViewCell里面添加UIWebView时需要注意在以下方法中的用法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return self.webView.height;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
//获取到webview的高度
// CGFloat height = [[self.webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
CGFloat heights = [self.webView sizeThatFits:CGSizeZero].height;
self.webView.frame = CGRectMake(self.webView.frame.origin.x,self.webView.frame.origin.y, SWIDTH, height);
[self.webView sizeToFit];
[_tableView reloadData];
[webView setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
[webView setHeight:webView.scrollView.contentSize.height];
[webView.scrollView setScrollEnabled:NO];
[_tableView reloadSections:[NSIndexSet indexSetWithIndex:2] withRowAnimation:UITableViewRowAnimationNone];
}
//添加事件监听
- (void)addObservers
{
[self.webView.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
{
if ([keyPath isEqualToString:@"contentSize"]) {
[self scrollViewContentSizeDidChange:change];
}
}
- (void)dealloc
{
//移除
[self.webView.scrollView removeObserver:self forKeyPath:@"contentSize"];
}
- (void)scrollViewContentSizeDidChange:(NSDictionary *)change
{
[self.webView setHeight:self.webView.scrollView.contentSize.height];
[_tableView reloadSections:[NSIndexSet indexSetWithIndex:2] withRowAnimation:UITableViewRowAnimationNone];
}
因为webView没有contentSize的属性,所以要用self.webView.scrollView
自己的一点小总结。希望也能帮到像我一样困惑的朋友
注:本文版权归作者所有,转载请注明出处
- tabViewCell里面添加webView
- tabViewCell重用
- tableView里面嵌套webView
- WebView里面调用打电话
- tabviewcell高度自适应
- WebView添加上下文菜单
- WebView添加进度条
- WebView添加localStorage存储
- webView 上添加按钮
- webView添加UserAgent后缀
- webview添加头尾视图
- 给WebView添加Cookie
- webview添加请求头
- webview httpheader 添加字段
- tabviewcell标记、移动、删除、插入
- tabviewcell 左滑 自定义按钮
- QCombobox里面添加treeview
- grid 里面添加控件
- 在Win10 Anaconda中安装Tensorflow
- lua学习记录
- 编码详解
- 如何转载博客
- python入门
- tabViewCell里面添加webView
- Decision Tree
- 利用第三方类 phpmailer 发邮件
- Vickate_iOS_设置 UIButton 点击时间间隔,防止连续重复点击
- DFS 枚举
- mysql创建用户并赋予权限无法进入情况
- iOS学习笔记--gif图片合成
- css3中-moz、-ms、-webkit,-o分别代表的意思,以及微信浏览器内核分析
- NOP