我是钛的新手,允许开发人员创建跨平台应用程序。我需要创建一个适用于Android和iOS的导航组。有没有明确的解决方案(因为Ti.UI.iPhone.createNavigationGrou()仅适用于iphone,
谢谢
答案 0 :(得分:7)
我有以下的NavigationController,它位于android和iphone文件夹中:
<强>机器人强>
var NavigationController = function() {
var self = this;
self.open = function(windowToOpen) {
//make "heavyweight" and associate with an Android activity
windowToOpen.navBarHidden = windowToOpen.navBarHidden || false;
if(!self.rootWindow) {
windowToOpen.exitOnClose = true;
self.rootWindow = windowToOpen;
}
windowToOpen.open();
};
self.close = function(windowToClose) {
windowToClose.close();
};
return self;
};
module.exports = NavigationController;
<强> iphone 强>
var NavigationController = function() {
var self = this;
function createNavGroup(windowToOpen) {
self.navGroup = Ti.UI.iPhone.createNavigationGroup({
window : windowToOpen
});
var containerWindow = Ti.UI.createWindow();
containerWindow.add(self.navGroup);
containerWindow.open();
};
self.open = function(windowToOpen) {
if(!self.navGroup) {
createNavGroup(windowToOpen);
}
else {
self.navGroup.open(windowToOpen);
}
};
self.close = function(windowToClose) {
if(self.navGroup) {
self.navGroup.close(windowToClose);
}
};
return self;
};
module.exports = NavigationController;
然后,您可以使用它(您将根据运行时自动获得正确的):
var NavigationController = require('NavigationController')
var MyView = require("ui/MyView");
var controller = new NavigationController();
var myView = new MyView(controller);
controller.open(myView);
您可以继续打开窗口,然后进入堆叠状态。注意我将控制器传递给第一个视图。你一直这样做:
controller.open(new SecondView(controller));
back
按钮会自动从堆栈中取出。如果您需要以编程方式执行此操作,只需告诉控制器将其关闭:
controller.close(myView);