求助,UIWebView拖到底部出现的excel删除多余空白列能去掉吗

UIWebView滚动到底部的代码 - 互联万物 - ITeye技术网站
博客分类:
实现UIWebViewDelegate中的
- (void)webViewDidFinishLoad:(UIWebView *)webView{
&&& NSInteger height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetH"] intValue];
&&& NSString* javascript = [NSString stringWithFormat:@"window.scrollBy(0, %d);", height];&&
&&& [webView stringByEvaluatingJavaScriptFromString:javascript];
}
原文地址:
/questions/3594851/how-can-i-scroll-programmatically-to-the-bottom-in-a-uiwebview
浏览: 366927 次
来自: 上海
这个现在已经广泛使用了嘛!
非常之详细
美女求认识
为什么不好使呢?iOS 7 UIWebView 304 cache bug, blank pages [iOS 7的UIWebView 304缓存错误,空白页] - 问题-字节技术
iOS 7 UIWebView 304 cache bug, blank pages
iOS 7的UIWebView 304缓存错误,空白页
问题 (Question)
I have a problem I have discovered in my app that has a UIWebView. iOS 7 caches a blank body 304 response, resulting in blank pages being shown when the user refreshes the UIWebView. This is not good user expierience and I'm trying to figure out how to solve this on the iOS side, as I do not have control over how Amazon S3 responds to headers (that's who I use for my resource hosting).
More details of this bug were found by these people:
I'd appreciate any help offered to how I can solve this on the app side and not the server side.
Thank you.
Update: fixed this bug using the bounty's suggestion as a guideline:
@property (nonatomic, strong) NSString *lastURL;
- (void)webViewDidFinishLoad:(UIWebView *)webView
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if ([self.webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"].length & 1)
NSLog(@"Reconstructing request...");
NSString *uniqueURL = [NSString stringWithFormat:@"%@?t=%@", self.lastURL, [[NSProcessInfo processInfo] globallyUniqueString]];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:uniqueURL] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:5.0]];
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
self.lastURL = [request.URL absoluteString];
return YES;
我有一个我在我的应用程序,有一个UIWebView中发现的问题。iOS 7缓存坯体304的反应,导致在空白页被显示在用户刷新UIWebView。这是不好的用户体验,我试图想出如何解决这个在iOS的一面,因为我没有在Amazon S3响应标头控制(这就是我用我的资源赋存)。这种错误的更多细节也被这些人发现:我要感谢任何帮助,给我如何解决在应用程序方面而不是服务器端。谢谢你更新:固定的错误使用的赏金的建议作为一个指导方针:@property (nonatomic, strong) NSString *lastURL;
- (void)webViewDidFinishLoad:(UIWebView *)webView
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if ([self.webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"].length & 1)
NSLog(@"Reconstructing request...");
NSString *uniqueURL = [NSString stringWithFormat:@"%@?t=%@", self.lastURL, [[NSProcessInfo processInfo] globallyUniqueString]];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:uniqueURL] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:5.0]];
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
self.lastURL = [request.URL absoluteString];
return YES;
最佳答案 (Best Answer)
As the other questions are to use the NSURLConnection every time, which seems like a bit of an overhead:
Why don't you execute a small javascript after the page was loaded (complete or incomplete) that can tell you if the page is actually showing? Query for a tag that should be there (say your content div) and give a true/false back using the
[UIWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('adcHeader')!=null"]
And then, should that return false, you can reload the URL manually using the cache-breaker technique you described yourself:
NSString *uniqueURL = [NSString stringWithFormat:@"%@?t=%d", self.url, [[NSDate date] timeIntervalSince1970]];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:uniqueURL] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:5.0]];
based on the discussion in the comments and some of the other answers, I think you might have the best solution manually changing the NSURLCache.
From what I gathered, you're mainly trying to solve a reload/reshow scenario. In that case, query the NSURLCache if a correct response is there, and if not delete the storedvalue before reloading the UIWebView.
based on your new results, try to delete the NSURLCache when it is corrupted:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
NSCachedURLResponse *cachedResponse = [[NSURLCache sharedURLCache]cachedResponseForRequest:request];
if (cachedResponse != nil && [[cachedResponse data] length] & 0)
NSLog(@"%@",cachedResponse.response);
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:request];
return YES;
We might have to refine the check if the cache is invalid again, but in theory this should do the trick!
当其他的问题是每一次使用NSURLConnection,这似乎有点像一个开销:你为什么不执行一个小JavaScript网页后装(完整或不完整),可以告诉你,如果页面上显示一个标签,应该有查询(说你的内容div)给一个真/假回用[UIWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('adcHeader')!=null"]
然后,应该返回false,你可以使用你自己的缓存刷新了手动断路器技术的URL:NSString *uniqueURL = [NSString stringWithFormat:@"%@?t=%d", self.url, [[NSDate date] timeIntervalSince1970]];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:uniqueURL] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:5.0]];
编辑基于在评论中讨论和一些其他的答案,我想你可能最好的解决办法手动更改NSURLCache。从我所收集的,你是试图解决一个重载/重新出现的场景。在这种情况下,查询NSURLCache如果一个正确的反应是存在的,如果不删除storedvalue之前重新加载UIWebView。[编辑] 2基于你的新结果,尝试删除NSURLCache当它被损坏:- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
NSCachedURLResponse *cachedResponse = [[NSURLCache sharedURLCache]cachedResponseForRequest:request];
if (cachedResponse != nil && [[cachedResponse data] length] & 0)
NSLog(@"%@",cachedResponse.response);
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:request];
return YES;
}我们可能要细化检查缓存无效了,但在理论上本应该做的伎俩!
答案 (Answer) 2
NSURL *URL = [NSURL URLWithString:@""];
NSURLRequest *request = [NSURLRequest requestWithURL:URL
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:30.0];
[myWebView loadRequest: request];
When creating NSURLRequest instance, you can set Cache Policy.
Hope it works!
NSURL *URL = [NSURL URLWithString:@""];
NSURLRequest *request = [NSURLRequest requestWithURL:URL
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:30.0];
[myWebView loadRequest: request];
创建实例时,你可以设置NSURLRequest,希望它缓存策略!
答案 (Answer) 3
You can implement a NSURLProtocol, and then in +canonicalRequestForRequest: modify the request to override the cache policy.
This will work for all requests made, including for static resources in the web view which are not normally consulted with the public API delegate.
This is very powerful, and yet, rather easy to implement.
Here is more information:
Reference:
Here is an example:
@interface NoCacheProtocol : NSURLProtocol
@implementation NoCacheProtocol
+ (void)load
[NSURLProtocol registerClass:[NoCacheProtocol class]];
+ (BOOL)canInitWithRequest:(NSURLRequest*)theRequest
if ([NSURLProtocol propertyForKey:@“ProtocolRequest” inRequest:theRequest] == nil) {
return YES;
return NO;
+ (NSURLRequest*)canonicalRequestForRequest:(NSURLRequest*)theRequest
NSMutableURLRequest* request = [theRequest mutableCopy];
[request setCachePolicy: NSURLRequestReloadIgnoringLocalCacheData];
//Prevent infinite recursion:
[NSURLProtocol setProperty:@YES forKey:@"ProtocolRequest" inRequest:request];
- (void)startLoading
//This is an example and very simple load..
[NSURLConnection sendAsynchronousRequest:self.request queue:[NSOperationQueue currentQueue] completionHandler:^ (NSURLResponse* response, NSData* data, NSError* error) {
[[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
[[self client] URLProtocol:self didLoadData:data];
[[self client] URLProtocolDidFinishLoading:self];
- (void)stopLoading
NSLog(@"something went wrong!");
您可以实现NSURLProtocol,然后在+canonicalRequestForRequest:修改请求重写缓存策略。这将为所有请求的工作,包括在Web视图,通常不与公共API代表了静态资源。这是非常强大的,然而,比较容易实现的。这里有更多的信息:参考这里有一个例子:@interface NoCacheProtocol : NSURLProtocol
@implementation NoCacheProtocol
+ (void)load
[NSURLProtocol registerClass:[NoCacheProtocol class]];
+ (BOOL)canInitWithRequest:(NSURLRequest*)theRequest
if ([NSURLProtocol propertyForKey:@“ProtocolRequest” inRequest:theRequest] == nil) {
return YES;
return NO;
+ (NSURLRequest*)canonicalRequestForRequest:(NSURLRequest*)theRequest
NSMutableURLRequest* request = [theRequest mutableCopy];
[request setCachePolicy: NSURLRequestReloadIgnoringLocalCacheData];
//Prevent infinite recursion:
[NSURLProtocol setProperty:@YES forKey:@"ProtocolRequest" inRequest:request];
- (void)startLoading
//This is an example and very simple load..
[NSURLConnection sendAsynchronousRequest:self.request queue:[NSOperationQueue currentQueue] completionHandler:^ (NSURLResponse* response, NSData* data, NSError* error) {
[[self client] URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
[[self client] URLProtocol:self didLoadData:data];
[[self client] URLProtocolDidFinishLoading:self];
- (void)stopLoading
NSLog(@"something went wrong!");
本文翻译自StackoverFlow,英语好的童鞋可直接参考原文:UIWebView隐藏右侧和底部的滚动条,去掉滚动边界的黑色背景
时间: 10:38:16
//,下侧条,滚动的
for (UIView *_aView in [myWebView subviews])
if ([_aView isKindOfClass:[UIScrollView class]])
[(UIScrollView *)_aView setShowsVerticalScrollIndicator:NO];
//右侧的滚动条
[(UIScrollView *)_aView setShowsHorizontalScrollIndicator:NO];
//下侧的滚动条
for (UIView *_inScrollview in _aView.subviews)
if ([_inScrollview isKindOfClass:[UIImageView class]])
_inScrollview.hidden = YES;
//上下滚动出边界时的黑色的图片
UIWebView滚动 ( 14:5
[(UIScrollView *)[[m_webView subviews] objectAtIndex:0] setBounces:NO];
$T.total > 0 && $T.page <= $T.pageNum}
{#foreach $T.data as r}
{$T.r.formt_tm}{#if $T.r.nickname}{#else}匿名{#/if}
{$T.r.content}
{#if $T.page > 1 && $T.pageNum > 1)
$T.s_num > 2}
{#for index = $T.s_num to $T.e_num}
$T.pageNum > $T.pageNavSize+ 2 && $T.s_num != $T.pageNum - $T.pageNavSize}
{#if $T.pageNum > 1}
{#if $T.pageNum != $T.page && $T.pageNum > 1}
<a href="javascript:void(0);" page="{$T.page 下一页
您的回应...
也许你感兴趣
(C)2012 本站提供的内容来源于广大网络用户,我们不保证内容的正确性。如果转载了您的内容,希望删除的请联系我们!今天看啥 热点:
UIWebView解决加载页面时背景一片空白问题,uiwebview一片空白
UIWebView加载过程中,在页面没有加载完毕前,会显示一片空白。为解决这个问题,方法如下:
方法1、让UIWebView背景透明。
webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;
[webView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@&webbg.png&]]];
先将webView的frame设为0, 在页面加载完成后再将frame设为原来大小.
在viewDidLoad中,在WebView上面覆盖一个背景视图。
self.webView=[[[UIWebView alloc]initWithFrame:self.view.bounds]autorelease];
[self.webView loadRequest:request];
[self.view addSubview:self.webView];
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@&gatewaybg.png&]];
imageView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
[self.view addSubview:imageView];
然后在WebView加载完成后把视图放到最上层或移除背景视图。
- (void)webViewDidFinishLoad:(UIWebView *)webView
// WebView放到最上层
[self.view bringSubviewToFront:self.webView];
// 或者可以把背景图移除
[self.webView removeFromSuperview];
相关搜索:
相关阅读:
相关频道:
Android教程最近更新

我要回帖

更多关于 删除多余空白页 的文章

 

随机推荐