Passing a url from tableview to webview
I know that this question has been asked and answered many times on this forum but unfortunately I still have not been able to grasp the concept correctly for my use case and I was hoping someone may be able to help.
My setup is a shows.js page that builds a tableview of all the shows being pulled from a database. The variable [path] contains a url that I would like to open in a webview when a row is clicked.
When I click on a table row it animates the new window across but does not load the webview. I would be very grateful if someone could help to point out where I am going wrong.
The code I am using to do this is:
xhr.onload = function() {
Ti.API.info(this.responseText);
var data = JSON.parse(this.responseText);
Ti.API.info(data);
for (var c=0;c<data.length;c++){
var row = Ti.UI.createTableViewRow();
var label = Ti.UI.createLabel({
text: data[c]['title'],
});
row.add(label);
row.url = data[c]['path'];
}
var tableview = Titanium.UI.createTableView({
data:data,
style:Titanium.UI.iPhone.TableViewStyle.PLAIN,
backgroundColor:'transparent',
headerView:headerView,
footerView:footerView,
maxRowHeight:140,
minRowHeight:70,
separatorStyle: Ti.UI.iPhone.TableViewSeparatorStyle.NONE
});
tableview.addEventListener('click',function(e)
{
Ti.API.info(e.rowData);
if (e.rowData.url)
{
var win = Titanium.UI.createWindow({
title:e.rowData.title
});
var webview = Titanium.UI.createWebView({
url:e.rowData.url
});
win.add(webview);
Titanium.UI.currentTab.open(win,{animated:true});
}
});
win.add(tableview);
} // end of xhr.onload function
1 Answer
-
Accepted Answer
i tried your code with fixed elements (url & title) it worked fine (webview show me the content of webview value.
did you checked the content of the e.rowData.url ? (with Ti.API.info(e.rowData.url) for example)