Search code examples
titaniumappcelerator

someView.visible = true not working in Titanium


I have a view that is set to show when a button is clicked.

This works but only if the button has been clicked once already.

So it works but not as it should eg. the first time the button is clicked.

I add the view to tableView as soon as it is created later in the code BTW.

here is some code to look at...

var vLabel = Ti.UI.createView({
    backgroundColor : 'white',
    width : '100%',
    height : 46,
    bottom : 25
});
var topBorderView = Ti.UI.createView({
    backgroundColor : '#d8d8d8',
    width : '100%',
    height : 1,
    top : 0
});
var aLabel = Ti.UI.createLabel({
    backgroundColor : 'white',
    objName : 'aLabel',
    text : "All Points - Takes a few moments to load.",
    font : {
        fontSize : 12
    },
    color : '#df0101',
    backgroundPaddingTop : 5,
    backgroundPaddingBottom : 3,
    left : '5%',
    width : '90%',
    height : 42,
    top : 2,
    zIndex : 6000,
    textAlign : Ti.UI.TEXT_ALIGNMENT_CENTER
});

vLabel.add(topBorderView);
vLabel.add(aLabel);

sortButton.addEventListener('click', function(e) {
    vLabel.visible = 1;
    vLabel.show();

    var loaders = getLoader();
    tableView.add(loaders);
    loaders.start();

    var tempRows = [];

    if (content.uid == 998) {

        if (e.index == 0) {
            tempRows = sortAllPoints(content, e.index);
            loaders.stop();
            vLabel.visible = false;
            tableView.remove(loaders);
            tableView.setData(tempRows, {
                animationStyle : Titanium.UI.iPhone.RowAnimationStyle.NONE
            });
            rowMainData = tableView.data;
            SearchBar.value = '';
        } else {
            tempRows = sortAllPoints(content, e.index);
            loaders.stop();
            vLabel.visible = false;
            tableView.remove(loaders);
            tableView.setData(tempRows, {
                animationStyle : Titanium.UI.iPhone.RowAnimationStyle.NONE
            });
            rowMainData = tableView.data;
            SearchBar.value = '';
        }
    }
}); 

Anyone have any clue as to why the view is showing on the 2nd button click but not the first?? Everything else works as it should eg. the loader animation

Thanks a lot, George.


Solution

  • Lateral Thinking! That's what you need. I had set the position of the view to be relative the bottom of the tableView. This worked while there was nothing in the table eg. it was loading or sorting the content. The answer was to make it's position relative to the top therefore no matter whether the content was being loaded or being sorted it is always visible. Sleep is good for this sort of thing!