我正在使用 XCode 4.2 版和 PhoneGap 1.5.0 版来开发 iOS 应用程序。使用下面的代码,我能够在页面上添加标签栏,但我无法在选择时导航到另一个页面。我使用 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");
}