TableView上的HeaderView放WebView

來源:互聯網
上載者:User

標籤:ima   style   sep   alt   現象   eva   image   contents   comm   

滑動起來沒有一絲卡頓現象親測

{

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 [email protected]"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
來源:簡書
著作權歸作者所有。商業轉載請聯絡作者獲得授權,非商業轉載請註明出處。

TableView上的HeaderView放WebView

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.