簡體   English   中英

在Titanium中使用側邊欄菜單導航時出現問題

[英]issue in navigating with sidebar menu in Titanium

嗨,我已經實現了側邊欄導航。 它具有3個選項,例如第一個屏幕(即index.js)是主屏幕中的側邊欄菜單。 問題是,當我通過側邊欄菜單轉到任何屏幕,然后再次返回到主屏幕,然后如果我按返回按鈕從主屏幕返回到上一次訪問的屏幕。預期的行為應該是如果我回到主屏幕退出應用程序。 那么如何跟蹤主屏幕。 如果我在主屏幕上,則無論如何應該退出應用程序,而不是從主屏幕轉到上次訪問的屏幕。

這是代碼。 代碼有點長。 有人可以幫忙嗎?

index.xml文件

<Alloy>
<Window id = "win" onOpen="openCurrentIssue">
    <View id="view1"  width="75%" height="Ti.UI.FILL" left="0%" >
        <TableView id="menuTable"></TableView>
    </View>
    <View id="view2"  width="Ti.UI.FILL" height="Ti.UI.FILL" backgroundColor="#A9F5A9" >

        <View id="viewcheck1" >
            <Label id="title" width="Ti.UI.SIZE" text="PolymerCommunique" height="Ti.UI.SIZE" textAlign="Ti.UI.TEXT_ALIGNMENT_CENTER"></Label>
            <ImageView id="menuImg" image="/images/menu.png" onClick="showsideBar" left="5"></ImageView>
        </View>

        <View id="viewcheck2"  width="Ti.UI.SIZE" height="Ti.UI.SIZE" backgroundColor="#A9F5A9" layout="vertical">

            <Label id="cIssue" text="Demo" width="Ti.UI.SIZE" height="Ti.UI.SIZE" textAlign="Ti.UI.TEXT_ALIGNMENT_CENTER" top="10" color="black"></Label>
            <ImageView id="cImage" width="Ti.UI.SIZE" height="Ti.UI.SIZE" top="45"></ImageView>
            <Button id="cButton" title="Advertiser"></Button>
        </View>

        <View id="viewBelow" width="150" height="Ti.UI.FILL" backgroundColor="#A9A5A9" left="-150" visible="false" top="40">
            <TableView id="menuTable"></TableView>
        </View>

    </View>
</Window>

index.js文件

var isMenu = false;
function showsideBar(e) {
try {
    if (isMenu) {
    $.viewBelow.animate({
        left : -150,
        //left :0,
        duration : 300,
        curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
    });
    isMenu = false;
} else {
    $.viewBelow.visible=true;
    $.viewBelow.animate({
        left : 0,    
        duration : 300,
        curve : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT
    });
    isMenu = true;
}

} catch(e) {
    Ti.API.info('Exception from index.js ' + e.value);
}}
function openCurrentIssue(e) {
try {

    var url = "http://polymerscommunique.com/api/current_issue.aspx";
    var jsonResponse;
    var response;



    var xhr = Ti.Network.createHTTPClient({
        onload : function() {
            Ti.API.info("Received text: " + this.responseText);
            jsonResponse = JSON.parse(this.responseText);

            $.cImage.image = jsonResponse[0].cover_image_url;
            $.cIssue.text = jsonResponse[0].issue_title;
        },

        onerror : function(e) {
            Ti.API.debug(e.error);
            alert('error');
        },
        timeout : 5000
    });
    xhr.open("GET", url);
    xhr.send();
} catch(e) {
    Ti.API.info('Exception from index.js ' + e.value);
}}
createTableRow = function(args) {
var row = Ti.UI.createTableViewRow();

var parentView = Ti.UI.createView({
    width : Ti.UI.FILL,
    height : 40,
    left : 5
});

var childView = Ti.UI.createView({
    height : Ti.UI.SIZE,
    width : Ti.UI.FILL,
    layout : "horizontal"
});

var image = Ti.UI.createImageView({
    image : args.leftImage,
    width : 18,
    height : 20,
    left : 5
});
childView.add(image);

var title = Ti.UI.createLabel({
    color : "white",
    text : args.title,
    left : 10,
    font : {
        fontSize : 17,
        fontWeight : 'bold'
    }
});
childView.add(title);

parentView.add(childView);
row.add(parentView);

var separator = Ti.UI.createView({
    bottom : 0,
    height : "1dp",
    width : Ti.UI.FILL,
    backgroundColor : "#303030"
});
row.add(separator);

return row;};
var rows = [];
rows.push(createTableRow({
title : 'Current Issue',
leftImage : '/home.png'}));

rows.push(createTableRow({
title : 'Past Issues',
leftImage : '/settings.png'}));

rows.push(createTableRow({
title : 'Subscribe',
leftImage : '/logout.png'}));

$.menuTable.setData(rows);
$.menuTable.addEventListener('click', function(e) {
 if(e.index=="0"){
    Alloy.createController('index', 'just');
}
if (e.index == "1") {
    showsideBar();
    Alloy.createController('pastissues', 'just');
}
else if (e.index == "2") {
    showsideBar();
    Alloy.createController('check','just');
}   });
$.win.open();

從表偵聽器中還可以看到另外兩個文件。 如果還需要,請告訴我。

您可以在主窗口控制器中收聽后退按鈕事件,然后在單擊時結束當前活動:

$.home.addEventListener('android:back', function (e) {
    var activity = Titanium.Android.currentActivity;
    activity.finish();
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM