0
votes

I have a question regarding the use of autolayout for arranging an unknown number of views. Suppose I have 4 labels label1...label4, they all have the same height/width and are one underneath the other with a 10pt vertical space between them. This labels display some info that I get from a server (and it might not exist for some of them)

The question is: if I have info for label1,label3 and 4 (or some other combination) how can I get the label to rearrange to always be where they are needed (one under the other with the 10pt vertical space). So in this situation label3 will be where label2 would have been if it had data...

2

2 Answers

3
votes

You're not taking the easiest way.

You should fill your labels "in order", eg. if you receive two lines of data, don't fill label 1 and label 4 and try to hide labels 2 and 3. Just fill labels 1 and 2, and hide the remaining labels.

Another reasonably suited solution would be to display your data in a UITableView. That way, you can display an arbitrary number of rows without having to handle these subtle cases.

1
votes

AS you already arranged the labels with 10pts distance don't disturb the labels arrangement.if you are getting data of 1st 3rd and 4th label,populate it in 1st, 2nd and 3rd labels and change the color of fourth label to clear color.The end user may not know that there is another label under it.As i am not able to see code I am stating this adjustment if you send a sample code i will give you a much better answer