TableView头部试图webview与原生交互

{
    UIView*view;
    UIImageView*image;
    CGFloatwebViewHeight;
}

- (void)viewDidLoad {

    [superviewDidLoad];

    self.table=  [[UITableViewalloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(self.webView.frame),kScreenWidth,kScreenHeight-  self.tabBarController.tabBar.frame.size.height)];

  self.table.delegate=self;

  self.table.dataSource=self;

  self.table.separatorStyle=UITableViewCellSelectionStyleNone;

  [self.viewaddSubview:self.table];

  view= [[UIViewalloc]initWithFrame:CGRectMake(0,0,kScreenWidth,kScreenHeight)];

  self.table.tableHeaderView=view;

  _webView= [[UIWebViewalloc]initWithFrame:CGRectMake(0,0,kScreenWidth,kScreenHeight)];

  [_webViewsetScalesPageToFit:YES];//大小自适应

  _webView.scrollView.scrollEnabled=NO;

  [self.webViewloadRequest:[[NSURLRequestalloc]initWithURL:  [NSURLURLWithString:@"你的URL"]]];

  [viewaddSubview:_webView];
  _webView.delegate=self;
  _webView.scrollView.delegate=self;
[_webView.scrollViewaddObserver:selfforKeyPath:@"contentSize"options:NSKeyValueObservingOptionNewcontext:nil];
}
- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context
{
    if([keyPathisEqualToString:@"contentSize"]) {
    webViewHeight= [[_webViewstringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"]floatValue];
    CGRectnewFrame=_webView.frame;
    newFrame.size.height=webViewHeight;
    _webView.frame= newFrame;
    [_webViewsizeToFit];
    CGRectFrame =view.frame;
    Frame.size.height= Frame.size.height+_webView.frame.size.height;
    view.frame= newFrame;
    [self.table setTableHeaderView:view];//这句话才是重点
    }
}

- (void)webViewDidFinishLoad:(UIWebView*)webView

{
  CGFloatsizeHeight = [[webViewstringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"]floatValue];
  self.webView.frame=CGRectMake(0,0,kScreenWidth, sizeHeight);
  stro.contentSize=CGSizeMake(kScreenWidth, sizeHeight+1);
}

- (void)didReceiveMemoryWarning {
  [superdidReceiveMemoryWarning];
}

#pragma mark返回每组行数

-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
  return5;
}

#pragma mark返回每行的单元格

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
    staticNSString*CellIdentifier =@"Cell";
    UITableViewCell*cell = [UITableViewCell   dequeueReusableCellWithIdentifier:CellIdentifier];
    if(!cell) {
    cell = [[commentsTableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifierIndexPa:indexPath];
  }
  returncell;
}

#pragma mark返回每行高度

- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
  return150;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 年前,他以为改革是为他而来,非他莫属。 年后,别人起了高楼,他却连车票都没买到。 01 年初,老板在大会上高声宣布...
    ld熊壮壮阅读 402评论 0 1
  • 开心的笑吧,今天 桂林下了连续两个星期的雨终于停了,南方的冬天没有下雪却出奇的冷。从二月初开始,微博微信扣扣空间都...
    紫薇忘了水葫芦阅读 196评论 0 0
  • 01 23年前我出生了 23年前你在一个小镇上生下了我,给你接生的护士是新来的没有结婚的小姑娘你羊水都留干了...
    一生如意阅读 389评论 0 1
  • 1. 了解这些名词含义 DSP:是Demand Side Platform的缩写。需求方管理平台DMP:是Data...
    成鹏9阅读 18,139评论 1 23
  • 今天下午补了一下午的笔记。好无语,平时工作内容不注重记录时间地点等,不仅没有及时记录工作内容,而且不利于反馈会珍,...
    阿_方阅读 381评论 0 0