我使用XCode版本4.2和PhoneGap版本1.5.0开发iOS应用程序。使用下面的代码,我可以在页面上添加标签栏,但是我无法将它导航到选择的另一个页面。我使用PhoneGap的NativeControls插件创建了标签栏。PhoneGap NativeControls选项卡选择
function onDeviceReady()
{
Cordova.exec("NativeControls.createTabBar"
var options = "bottom";
window.onorientationchange = function() {
var orientation = window.orientation;
switch(orientation) {
case 0:
Cordova.exec("NativeControls.showTabBar", options);
/* Add a descriptive message on "Handling iPhone or iPod touch Orientation Events" */
document.getElementById("currentOrientation").innerHTML="Now in portrait orientation (Home button on the bottom).";
break;
case 90:
Cordova.exec("NativeControls.showTabBar", options);
document.getElementById("currentOrientation").innerHTML="Now in landscape orientation and turned to the left (Home button to the right).";
break;
case -90:
Cordova.exec("NativeControls.showTabBar", options);
document.getElementById("currentOrientation").innerHTML="Now in landscape orientation and turned to the right (Home button to the left).";
break;
default:
Cordova.exec("NativeControls.showTabBar", options);
document.getElementById("currentOrientation").innerHTML="Now the orientation must be -180. default: case: ";
break;
}//end switch
}//end window.orientationchange
Cordova.exec("NativeControls.showTabBar", options);
Cordova.exec("NativeControls.createTabBarItem", "Wineries", "Wineries", null, "1", options);
Cordova.exec("NativeControls.createTabBarItem", "Wines", "Wines", "www/Wine.png", "2", {onSelect: function() {location.href = "Review.html" }});
Cordova.exec("NativeControls.createTabBarItem", "Tours", "Tours", null, "3", options);
Cordova.exec("NativeControls.createTabBarItem", "Non-Mobile", "Non-Mobile", null, "4", options);
Cordova.exec("NativeControls.showTabBarItems", "Wineries", "Wines", "Tours", "Non-Mobile");
Cordova.exec("NativeControls.selectTabBarItem", "Wineries");
}
但是,这段代码根本无法改变页面的选择。当我用下面的代码
Cordova.exec("NativeControls.createTabBarItem", "Wines", "Wines", "www/Wine.png", "2", {onSelect: function() {location.href = "Review.html" }});
编辑同样的情况。我应该在第二页重复相同的代码吗?如果是的话,我应该调用这个方法?
function onDeviceReady()
{
var nc = window.plugins.nativeControls;
nc.createTabBar();
nc.createTabBarItem("Wineries", "Wineries", "www/grape.png", {onSelect: function() {location.href = "index.html" }});
nc.createTabBarItem("Wines", "Wines", "www/Wine.png", {onSelect: function() {location.href = "Review.html" }});
nc.createTabBarItem("Tours", "Tours", "www/tour.png", null);
nc.createTabBarItem("Non-Mobile", "Non-Mobile", "", null);
nc.showTabBar();
nc.showTabBarItems("Wineries", "Wines", "Tours", "Non-Mobile");
nc.selectTabBarItem("Wineries");
}