1

一般的なJSを使用してスクロール可能なメニューを作成しています。

メニューの項目は、他の2つのコンポーネントを含むビューです。アイコンのimageViewと、このメニューのテキストのラベルです。

動作は奇妙で、AndroidとiOSのシミュレーターでは同じではありません。

androidでは、ラベルまたはimageviewをクリックすると、「キャッチされていないTypeError:プロパティを読み取れません...」が表示されます。iphoneでは、何も起動しません。

他の場所(まだビューアイテム内)をクリックしても、画像や唇、たとえば端などではクリックしない場合、それは完璧に機能します!!

コードは次のとおりです。

関数menuIcons(itemTab){

var menuMain = Ti.UI.createView({
    layout : 'vertical',
    backgroundColor : '#333333',
    height : 125,
    bottom : 10,
    left : 10,
    right : 10,
    borderRadius : 5.0
});

var menuFirstLine = Ti.UI.createScrollView({
    scrollType : 'horizontal',
    contentHeight : 120,
    contentWidth : 'auto',
    layout : 'horizontal',
    height : 120,
    marginLeft : 5
});

var items = [];
var menuIconsItem = require('view/module/menuIconsItem');

for(var i in itemTab) {
    var page = itemTab[i].page;

    items[i] = new menuIconsItem(itemTab[i]);

    (function(itemsEvent) {
        itemsEvent.id = itemTab[i].id;
        itemsEvent.addEventListener('click', function(e) {

            Ti.App.fireEvent('main_menu_' + itemsEvent.id, {
                id : e.source.id
            });
        })
    })(items[i]);

    menuFirstLine.add(items[i]);
}
menuMain.add(menuFirstLine);
return menuMain;

}

module.exports = menuIcons;

および必要なアイテムのコード(var menuIconsItem = require('view / module / menuIconsItem');):

関数menuIconsItem(item){

// path for images on Android  besoin de centraliser tout ca
var pathImages = '';

var itemImage = Ti.UI.createImageView({
    image : item.imageLink,
    width : 64,
    height : 64,
    top : 15
});

var itemLabel = Ti.UI.createLabel({
    color : '#afafaf',
    text : item.text,
    font : {
        textAlign : 'center'
    },
    height : 40,
    top : 80
});

var menuItem = Ti.UI.createView({
    width : 120,
    height : 120,
    backgroundColor : '#424242',
    top : 5,
    left : 5
});

menuItem.add(itemImage);
menuItem.add(itemLabel);

return menuItem;

}

module.exports = menuIconsItem;

4

1 に答える 1

2

ラベルと画像ビューのIDも設定する必要があります。

于 2012-05-11T12:41:41.670 に答える