开发者

window opens twice or more on single click in dynamic tableview - appcelerator

So i have a dynamic tableview. when i click on one of the rows i got a new screen. It works, but on the top left the back button shows the title of the current window, so i have to click min 2 times on, to get back to the tableviews tab. Any idea why?

var win = Titanium.UI.currentWindow;
Titanium.include('strip_tags.js');  
var tab = Titanium.UI.currentTab;
var ta开发者_高级运维bleView = Titanium.UI.createTableView({top:43,        
separatorStyle: 'none',
    backgroundColor:'transparent'});
    win.add(tableView);
    Ti.UI.currentWindow.addEventListener('focus', function() {
        loadTweets();

});


function loadTweets()
{


var rowData = [];

var loader = Titanium.Network.createHTTPClient();

loader.open("GET","url", true);

loader.onload = function() 
{
    var tweets =JSON.parse(this.responseText);



    for (var i = 0; i < tweets.length; i++)
    {
        var id = tweets[i].id;
        var title = tweets[i].name; // The tweet message
        var special=tweets[i].special;
        if(special>0) {
            var price=tweets[i].special;
            var color2='#4C6B22';
        } else {
            var color2='#fff';
            var price=tweets[i].price;
        }


        var thumb = tweets[i].thumb; // The profile image
        title=title.replace('®', '');
        title=title.replace('™', '');


        var row = Titanium.UI.createTableViewRow({height:'auto',top:20 , backgroundImage:Ti.Filesystem.resourcesDirectory + '/images/row_bg.png', borderWidth:0, separatorStyle: 'none'});


        var post_view = Titanium.UI.createView({
            height:'auto', 
            layout:'vertical',
            top:0,
            right:5,
            bottom:0,
            left:5,
            borderWidth:0,
            height:49


        });

        var av_thumb = Titanium.UI.createImageView({
            url:thumb, // the image for the image view
            top:0,
            left:0,
            height:48,
            width:48
        });
        post_view.add(av_thumb);

        var av_title = Titanium.UI.createLabel({
            text:title,
            left:54,
            width:210,
            top:-30,
            bottom:2,
            height:16,
            textAlign:'left',
            color:'#fff',
            font:{fontFamily:'Trebuchet MS',fontSize:14,fontWeight:'bold'}
        });
        post_view.add(av_title);

        var av_desc = Titanium.UI.createLabel({
            text:special,
            left:270,
            top:-20,
            color:'#fff',
            bottom:2,
            height:'auto',
            width:236,
            textAlign:'left',
            font:{fontSize:14}
        });
        post_view.add(av_desc);

        row.add(post_view);

        row.className = "item"+i;


        row.thisTitle = title;
        row.thisId = id;

        rowData[i] = row;
    }

        var winCount = Titanium.UI.createLabel({
            text:tweets.length+' blalba',
            height:43,
            top:0,
            left:0,
            width:320,
            height:50,
            textAlign:'center',
            color:'#fff',
            backgroundImage:Ti.Filesystem.resourcesDirectory + '/images/row_bg.png',
            font:{fontFamily:'Trebuchet MS',fontSize:14,fontWeight:'bold'}
        });


        win.add(winCount);

    tableView.setData(rowData);
    tableView.addEventListener('click', function(e){



    var w2 = Titanium.UI.createWindow({
            title:e.rowData.thisTitle,
            url:'cikk.js',
            barColor:'#000',
            backgroundImage:Ti.Filesystem.resourcesDirectory + '/images/winbg.png'
        });
        w2.stringProp1 = strip_tags(e.rowData.thisId);

        tab.open(w2, {
            animated:true
        });



}   

)};

loader.send();
}


my hunch is the that the eventListener focus is getting called twice and that is causing the tweets to get loaded twice which then cause the tableView eventListener to get loaded twice.

if you are going to use focus to add the eventListener, then I would suggest using blur to remove the eventListener.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜