【问题标题】:Alloy navigation between windows窗口之间的合金导航
【发布时间】:2014-10-10 10:24:01
【问题描述】:

我有 3 个合金屏幕(加速器):

index.xml

<Alloy>
    <Window class="container">
        <ImageView id = "actor" image="/images/f_logo.jpg"></ImageView>
        <Label id = "bienvenue"  onClick="doClick" > Bienvenue </Label>
        <Label id = "apropos"> A propos </Label>
    </Window>
</Alloy>

welcome.xml

<Alloy>
    <Window class = "win2container">
        <ImageView id = "bienvenue2" image="/images/f_logo.jpg"></ImageView>
        <View id="texte" onClick="showTable">
            <Label text="Afficher la liste" ></Label>
        </View>
    </Window>
</Alloy>

liste.xml

<Alloy>
<Tab title="Basic">
    <Window title="Basic">
        <ListView id = "liste" itemClick="onItemClick">
            <ListSection>
                <ListItem title="Row 1"></ListItem>
                <ListItem title="Row 2"></ListItem>
                <ListItem title="Row 3"></ListItem>
                <ListItem title="Row 4"></ListItem>
                <ListItem title="Row 5"></ListItem>
                <ListItem title="Row 6"></ListItem>
                <ListItem title="Row 7"></ListItem>
                <ListItem title="Row 8"></ListItem>
                <ListItem title="Row 9"></ListItem>
                <ListItem title="Row 10"></ListItem>
                <ListItem title="Row 11"></ListItem>
                <ListItem title="Row 12"></ListItem>
            </ListSection>
        </ListView>
    </Window>
</Tab>
</Alloy>

index.js(有效)

function doClick(e) {
var win = Alloy.createController("welcome").getView();
win.open();
}

$.index.open();

welcome.js(我要打开列表窗口)

function showTable(e){
var liste = Alloy.createController("liste");
liste.getView().open();
}

当我点击索引标签时,它会打开欢迎窗口,当我点击欢迎视图时它什么也不做,我的目标是发现如何使用合金在许多窗口(查看文件)之间导航。

其次,我在 google 上看到,像这样关闭以前的窗口是一个好习惯:

$.win.close();
$.win = null;

当我在 $.win.open() 之后将此代码放入 index.js 时,它不起作用(即:我出错了)

function doClick(e) {
var win = Alloy.createController("bienvenue").getView();
win.open();
$.win.close(); // or win.close() ?
$.win = null; // or win = null ?
}

有什么建议吗?我试了很多次都没有成功。

谢谢大家。

【问题讨论】:

    标签: view window titanium appcelerator


    【解决方案1】:

    关于 close() 是一种好的做法,是的,也不是。

    如果您希望窗口在用户使用后退按钮导航返回时存在,那么不,因为从本质上讲,它将被关闭。

    function doClick(e) {
     var win = Alloy.createController("bienvenue").getView();
        win.open();
        $.win.close(); // DEFINITELY $.win, as you created a var named win for your new window
        $.win = null; // and $.win is the equivalent of findViewById("win")
    }
    

    顺便说一句,您打开窗口的方式将无法利用导航(Android 中的硬件,iOS 导航中的软返回)

    对于 Android,我通常会编写自己的管理器来确定当前哪个窗口具有焦点,以及当您返回时会发生什么。

    在 iOS 中,您应该使用类似的方法将窗口序列添加到导航部分

    var controllerWindow = Alloy.createController("bienvenue") // changed win to controllerWindow for clarity
    
    
    var nav = Titanium.UI.iOS.createNavigationWindow({
                       window: controllerWindow
                    });
    nav.open();
    

    【讨论】:

    • 有什么知名且经过测试的库可以跨平台为我做到这一点吗?
    【解决方案2】:

    我相信您所寻求的答案是如何在打开新窗口的同时关闭触发操作的上一个窗口。

    您的示例只是创建并打开一个新窗口。然后关闭它。您需要做的是关闭前一个窗口。如果您为上一个窗口提供了id,那么您可以使用$.id.close() 关闭它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-08
      • 1970-01-01
      • 1970-01-01
      • 2012-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多