Override Back Button Event on Tab Window
I'm trying to change the back button on a window on a tab.
Currently, the back button goes back to the main window on the tab.
I'd like to change the event to swap out a view… showTableView() or showWebView().
I'm trying to optimize my code to only use a few windows and one web view… similar to Kevin's Snapost example.
// subwindow.js
var win = Titanium.UI.currentWindow;
// Titanium.UI.currentWindow.backgroundColor = 'black';
// Titanium.UI.currentWindow.barColor = 'black';
// Titanium.UI.currentWindow.backgroundImage = '../images/bg.png';
Titanium.include('tableview.js');
Titanium.include('webview.js');
// create view container (allows us to do nice transitions)
var viewContainer = Titanium.UI.createView();
// add main content views to container
viewContainer.add(webView);
viewContainer.add(tableView);
// intialize
webView.visible = false;
// modify view visibility for navigation
function showWebView(rowData) {
alert( rowData.url );
webView.url = rowData.url;
viewContainer.animate({view:webView,transition:Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT});
win.title = rowData.title;
tableView.visible = false;
webView.visible = true;
}
function showTableView() {
viewContainer.animate({view:tableView,transition:Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT});
win.title = 'Best Practices';
tableView.visible = true;
webView.visible = false;
}
// setup the window
win.add(viewContainer);
// create table view event listener
tableView.addEventListener('click', function(e)
{
if (e.rowData.test) {
//alert( 'showTableView: ' );
showTableView();
}
else if (e.rowData.url) {
//alert( 'showWebView: ' + e.rowData.url );
showWebView(e.rowData);
}
});
1 Answer
-
Accepted Answer
The only way I know to do that would be to replace that button with your own button. There's a blur and close event for a window, but I don't think it fires in time to do a preventDefault on it and use your own function.
Something like this should work:
var win = Ti.UI.currentWindow; var b = Titanium.UI.createButton({title:'title'}); b.addEventListener('click', function() { // do something }); win.leftNavButton = b;