zoukankan      html  css  js  c++  java
  • TableView上的HeaderView放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;

    }



    作者:iOS我称王
    链接:http://www.jianshu.com/p/66b367b8b3ff
    來源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 相关阅读:
    01、python数据分析与机器学习实战——Python可视化库Seaborn
    01、python数据分析与机器学习实战——Python可视化库Seaborn
    01、python数据分析与机器学习实战——Python可视化库Seaborn
    Sql Server增加字段、修改字段、修改类型、修改默认值 ALTER
    生产者/消费者模式的理解及实现
    生产者/消费者模式的理解及实现
    C# 通过Process.Start() 打开程序 置顶方法
    C# 通过Process.Start() 打开程序 置顶方法
    [C#.Net]判断文件是否被占用的两种方法
    VS2010启动多个实例调试
  • 原文地址:https://www.cnblogs.com/Ghosgt/p/7410979.html
Copyright © 2011-2022 走看看