Changing label text in tableView headerView moves the header
I've got a tableView with a headerView that contains a label. I want to update the text of the label, but when I do so, the headerView moves, jumping to the middle of the window.
Here's an example. Click the button and see what happens. Any thoughts on a workaround?
var win = Ti.UI.createWindow({});
var data = [];
data[0] = Ti.UI.createTableViewRow({title:'Row 1'});
data[1] = Ti.UI.createTableViewRow({title:'Row 2'});
data[2] = Ti.UI.createTableViewRow({title:'Row 3'});
data[3] = Ti.UI.createTableViewRow({title:'Row 4'});
var headerView = Ti.UI.createView({height:'auto'});
var headerLabel = Ti.UI.createLabel({
text:'Here is some text for the header label.',
height:'auto',
left:10,
right:10
});
headerView.add(headerLabel);
var tableView = Ti.UI.createTableView({
style:Titanium.UI.iPhone.TableViewStyle.GROUPED,
top:0,
right:0,
left:0,
headerView:headerView,
data:data
});
win.add(tableView);
var button = Ti.UI.createButton({
title:'Change Header',
height:40,
width:150,
bottom:10
});
button.addEventListener('click', function()
{
headerLabel.text = 'This is some different text.';
});
win.add(button);
win.open();
2 Answers
-
One workaround is changing the
headerLabel.height
from 'auto' to a fixed value, for ex.var headerLabel = Ti.UI.createLabel({ text:'Here is some text for the header label.', height:25, left:10, right:10 });
-
Goran,
That works, unless you change the height value. So, for example, if you set the initial height to 25, but change it to 35 in the event listener, the headerView moves to the middle of the window, just as if the height were initially set to 'auto'.
I reported this and it has been filed as a bug, so hopefully it will get fixed in 1.5.
– Kenn