简体   繁体   中英

Sencha touch 2.0 and iphone : add element to panel dynamically and setActiveItem

I am trying to add dinamically a panel item to a main panel with a card layout which has initially one panel in it. After one event (a tap) i build dinamically a new panel and I add it to the main panel, after this i try to set the new panel item like the active one via setActiveItem

Things work ok on Android but not on iphone.

Exactly i have this app.js:

Ext.Loader.setConfig({enabled: true});
Ext.setup({
viewport: {
    autoMaximize: false
},
onReady: function() {
    var app = new Ext.Application({
        name: 'rpc',
        appFolder: 'app',           
        controllers: ['Home'],
        autoCreateViewport: false,
        launch: function () {
            Ext.create('Ext.Panel',{
                fullscreen: true,           
                layout: {
                    type : 'card',
                    animation:{
                        type:'slide'
                        ,duration :3000
                    }
                },
                defaults: {     /*definisce le caratteristiche di default degli elementi contenuti..??*/
                    flex: 1
                },
                items:[{
                    title: 'Compose',
                    xtype: 'griglia'
                }]
            });
        }
    });
}
});

In a controller i have

            .....
        .....
        var grigliaPan=button.up('griglia');
        var mainPan=grigliaPan.up('panel');

        var html=
            '<img src="img/'+segnoScelto+'_big.png" />'
            +'<h1>'+segnoScelto+'</h1>'
            +'<p>'+previsione+'</p>'
            +'</br></br>';
        if (typeof mainPan.getComponent(1) == 'undefined'){
                        var previsioPan = Ext.widget('previsio');
                        previsioPan.setHtml(html);

                        //here i create a button for going home panel
                        var backButton=new Ext.Button({
                            ui  : 'decline',
                            alias: 'widget.backbutton',
                            text: 'Home Page',
                            width : 150,
                            height:100
                        })

                        previsioPan.add(backButton);
                        var it=mainPan.getItems();
                        alert (it['keys']);     //this prints : ext-griglia-1
                        mainPan.add(previsioPan);
                        var it=mainPan.getItems();
                        alert (it['keys']);     //this prints : ext-griglia-1,ext-previsio-1
                        //
        }
        mainPan.getLayout().setAnimation({type: 'slide', direction: 'left', duration:1000});
        //mainPan.setActiveItem(1);
        var pree=mainPan.getAt(1);
        //pree.show();
        //mainPan.setActiveItemm(pree);
        mainPan.setActiveItem('ext-previsio-1');

The three form of setActiveItem() are ok for Android and falls with iPhone. Can somebody please show me what is the right way to set the new active item added dinamically on the iphone ?

The problem should not be with the add() function cause i can see the new item via the getItems() added in main panel after the add().

by following code you can understand that thisCell is added later after creation of thisRow.

var thisRow = new Ext.Panel({ 
                 layout: { type: 'hbox', align: 'stretch', pack: 'center' },
                 id: 'row' + (rowCount + 1), 
                 defaults: { flex: 1 } 
              });

        // Now we need to add the cells to the above Panel:
var thisCell = new Ext.Panel({
             cls: 'dashboardButton',
                 layout: { type: 'vbox', align: 'center', pack: 'center' },
         items: [{
                      xtype: 'image',
                      src: 'some image url',
                      height: '70px',
                      width: '100px',
                 }]
               });
thisRow.add(thisCell);

hope this will help you to achieve your desired output...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM