I need to load an HTML inside my IOS app but i need it to be an editable HTML so my aproach was the following:
I created a NSString with format so i could make a String with the HTML code depending on some variables:
NSString *googleGraphCode = [NSString stringWithFormat:@""<"html>"<"body>"<"div id=\"%@\">"<"/div>"<"script type=\"%@\" src=\"%@\"> google.load('visualization', '1.0', {'packages':['corechart']}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); %@ data.addRows([%@]); var options = {'title':'%@', 'width':%i, 'height':%i}; var chart = new google.visualization.PieChart(document.getElementById('%@')); chart.draw(data, options); }"<"/script>"<"/body>"<"/html>" , chartID, javaScriptCall, AJAX_Api, javaScriptCall, columns, rows, title, widht, height, chartID];
Then I Loaded the webView with the HTMLString:
[_graphHostView loadHTMLString:googleGraphCode baseURL:nil];
I get the code in the NSLog and i get this:
"<"html>"<"body>"<"div id="chart_div">"<"/div>"<"script type="text/javascript" src="https://www.google.com/jsapi">"<"script type="text/javascript"> google.load('visualization', '1.0', {'packages':['corechart']}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('string', 'Tipo'); data.addColumn('string', 'CantidadGasto'); data.addRows([['Gastos', 30000], ['Ingresos', 50000]]); var options = {'title':'Su gráfica de balance:', 'width':320, 'height':300}; var chart = new google.visualization.PieChart(document.getElementById('chart_div')); chart.draw(data, options); }"<"/script>"<"/body>"<"/html>
But the webView on the device doesn't show anything.
Note: I used "<" before html code so Stackoverflow shows it on the question so "<"html> = regular html begining.