【问题标题】:FusionCharts on iOS: Invisible second chartiOS 上的 FusionCharts:隐形第二张图表
【发布时间】:2015-07-17 04:23:42
【问题描述】:

我在 iOS 应用程序上使用 FusionCharts。

目前我有一个带有两个不同 UIWebViews 的视图控制器,它们从不同的 html 文件加载两个不同的图表。

问题是两个图表都被渲染了,但其中一个是不可见的,正如您在屏幕截图中看到的那样。

一次只能处理一张图表。我该如何解决这个问题?!

screenshot

【问题讨论】:

  • 你检查是否有重复的ID?您使用的是最新的 FusionCharts (3.3.0.18739) 吗?

标签: ios fusioncharts


【解决方案1】:

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

@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

【讨论】:

    【解决方案2】:

    此回复可能为时已晚。我遇到了与 HighCharts 相同的问题。 你不需要继承 UIWebView。您需要为每个图表提供不同的 Javascript 文件。那会起作用的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-09
      • 2023-04-08
      相关资源
      最近更新 更多