0

I have a collection view, that no matter what device there are 4, equally sized cells that fit in an area on the screen. That area is the device height-20-50-3/2. 20 is the status bar, 50 is a cancel button and 3 is 1px line at top, between the cell and bottom. On the 4" screen the cell size in portrait is also the same size in landscape, so its always the same. But on the 4S, the cells get bigger. I call

[self.collectionView.collectionViewLayout invalidateLayout];
[self.collectionView reloadData];

On rotation, but if i scroll through the cells, some of the labels move down because in the cells initWithFrame: method i set the text labels frame like

        _textLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, frame.size.height-27.5, 148.5, 23)];

So it looks like this line is being called because they move, but if i scroll down, then back up then the label is back in its previous place. How can i fully reload this data and make it resize all the content of the cells without it messing around and reframing when i scroll?

Heres an image of the issue, the text label should either all be at the bottom, or where the middle one is:

enter image description here

Here is my code for the cell and collection view: https://gist.github.com/MaxHasADHD/cab99e06c7d1e2cf78bb

Maximilian Litteral
  • 3,059
  • 2
  • 31
  • 41
  • Can you try this [_textLabel setNeedsDisplay]; – PedroAGSantos Sep 23 '13 at 12:39
  • during rotation or in the initWithFrame method? – Maximilian Litteral Sep 23 '13 at 12:42
  • Like this: _textLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, frame.size.height-27.5, 148.5, 23)]; [_textLabel setNeedsDisplay]; – PedroAGSantos Sep 23 '13 at 12:53
  • Oh, No that did not work. I don't know if initWithFrame is actually being called more than once, I just assume it is because the text label is in the 2 places it could be, but they go randomly. On the 4" screen they are at the bottom because thats the cell size for portrait also, but on 3.5" they change and for some reason, only the label is changing when I scroll around. If initWithFrame was actually called again i think the image would be bigger also. If i scrolled down, then back up to those 3 cells in the image, the labels would be different again. – Maximilian Litteral Sep 23 '13 at 12:59
  • Can you show how you using the cells ? – PedroAGSantos Sep 23 '13 at 13:03
  • I uploaded an image, They are tabs. Here is the code though for the cell and collection view: https://gist.github.com/MaxHasADHD/cab99e06c7d1e2cf78bb – Maximilian Litteral Sep 23 '13 at 13:08
  • You current code is like this _textLabel.textAlignment = NSTextAlignmentCenter; [self.contentView addSubview:_textLabel]; [_textLabel setNeedsDisplay]; can you try _textLabel.textAlignment = NSTextAlignmentCenter; [_textLabel setNeedsDisplay]; [self.contentView addSubview:_textLabel]; – PedroAGSantos Sep 23 '13 at 13:21
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/37886/discussion-between-subspider-and-maxhasadhd) – PedroAGSantos Sep 23 '13 at 13:23

0 Answers0