获得响应后第二次没有加载html字符串

时间:2016-10-24 06:53:01

标签: html objective-c uiwebview

在我的项目中,我在UIWebView中工作。在我获取Web服务响应之后,我将一个HTML文件转换为NSString然后我加载到UIWebView它工作正常,它第一次再次工作我正在点击它没有加载的Web服务。以下是我的代码帮助我提前感谢

//After getting response from web service
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"graph" ofType:@"html"];
htmlString = [[NSString alloc] initWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
htmlString = [htmlString stringByReplacingOccurrencesOfString:@"%@" withString:[timeArr componentsJoinedByString:@""]];
[self.webView loadHTMLString:htmlString baseURL:nil];

第一次加载,但第二次没加载,

我尝试了[self.webView reload];

HTML文件

<html>
    <head>
        <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
        <script type="text/javascript">
            google.charts.load('current', {'packages':['timeline']});
            google.charts.setOnLoadCallback(drawChart);
            function drawChart() {
                var container = document.getElementById('timeline');
                var chart = new google.visualization.Timeline(container);
                var dataTable = new google.visualization.DataTable();

                dataTable.addColumn({ type: 'string', id: 'event' });
                dataTable.addColumn({ type: 'date', id: 'Start' });
                dataTable.addColumn({ type: 'date', id: 'End' });
                dataTable.addRows([ 'stop', new Date(2001, 2, 3,00,00,00), new Date(2001, 2, 3,03,21,02) ],
                                  [ 'drive', new Date(2001, 2, 3,03,21,02), new Date(2001, 2, 3,03,22,25) ],[ 'stop', new Date(2001, 2, 3,03,22,25), new Date(2001, 2, 3,05,27,30) ],[ 'drive', new Date(2001, 2, 3,05,27,30), new Date(2001, 2, 3,05,28,41) ],[ 'stop', new Date(2001, 2, 3,05,28,41), new Date(2001, 2, 3,06,31,11) ],[ 'drive', new Date(2001, 2, 3,06,31,11), new Date(2001, 2, 3,06,31,36) ],[ 'stop', new Date(2001, 2, 3,06,31,36), new Date(2001, 2, 3,06,37,55) ],[ 'drive', new Date(2001, 2, 3,06,37,55), new Date(2001, 2, 3,07,33,15) ],[ 'idle', new Date(2001, 2, 3,07,33,15), new Date(2001, 2, 3,08,03,05) ],[ 'idle', new Date(2001, 2, 3,08,03,05), new Date(2001, 2, 3,08,32,55) ]);

                chart.draw(dataTable);
            }
        </script>
    </head>
    <body>
        <div id="timeline" style="height: 280px;"></div>
    </body>
    </html>

0 个答案:

没有答案