0

我在 iOS 上使用FusionCharts 。我在使用融合图表加载多个UIWebView时遇到问题。问题是只有一个 webview 正确显示图表。第二个加载并呈现图表,但只有在我滚动视图后才能正确显示。

仅在滚动视图后才能正确呈现图表。什么可能导致这种行为?

谢谢。

4

1 回答 1

0

这个问题的问题在于 UIWebView 它自己为了清楚的解释查看下面的链接 http://double-slash.net/2010/10/18/using-multiple-ios-uiwebview-objects/它可以通过两种方式修复通过采用自旋锁机制或通过自定义 UIWebview 增加运行循环的渲染时间。

@interface FCXTCustomWebView ()

@property (assign) id idelegate;

@end

@implementation FCXTCustomWebView

- (id)init
{
self = [super init];
if (self)
{
    self.delegate = self;
}

return self;
}

- (id) initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
    self.delegate = self;
}

return self;
}

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
    // Initialization code
    self.delegate = self;
}
return self;
}

- (void)setDelegate:(id<UIWebViewDelegate>)delegate
{
_idelegate = delegate;
}

- (void)stopRunLoop
{
CFRunLoopRef runLoop = [[NSRunLoop currentRunLoop] getCFRunLoop];
CFRunLoopStop(runLoop);
}

- (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[self performSelector:@selector(stopRunLoop) withObject:nil afterDelay:.01];

if ([_idelegate respondsToSelector:@selector(webView:didFailLoadWithError:)])
{
    [_idelegate webView:webView didFailLoadWithError:error];
}
}

- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if ([_idelegate respondsToSelector:@selector(webView:shouldStartLoadWithRequest:navigationType:)])
{
    return [_idelegate webView:webView shouldStartLoadWithRequest:request navigationType:navigationType];
}
else
{
    return YES;
}
}

- (void) webViewDidFinishLoad:(UIWebView *)webView
{
[self performSelector:@selector(stopRunLoop) withObject:nil afterDelay:.01];

if ([_idelegate respondsToSelector:@selector(webViewDidFinishLoad:)])
{
    [_idelegate webViewDidFinishLoad:webView];
}
}

- (void) webViewDidStartLoad:(UIWebView *)webView
{
[self performSelector:@selector(stopRunLoop) withObject:nil afterDelay:.1];
if ([_idelegate respondsToSelector:@selector(stopRunLoop)])
{
    [_idelegate webViewDidStartLoad:webView];
}
}

- (void) loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
{
[super loadHTMLString:string baseURL:baseURL];
CFRunLoopRunInMode((CFStringRef)NSDefaultRunLoopMode, 1.5, NO);
}

@end
于 2013-03-27T06:21:07.083 回答