11

So I just tried subclassing UITableViewHeaderFooterView and aligning the labels the way I want by overriding -layoutSubviews.

When I call super and change a label's frame, however, the app appears to be stuck in an infinite -layoutSubviews loop.

My code looks like this:

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.textLabel.frame = CGRectMake(10.0, 10.0, 300.0, 40.0);
}

Any ideas on how to fix this?

Christian Schnorr
  • 10,768
  • 8
  • 48
  • 83
  • I ended up subclassing from UIView and adding these labels myself. – Christian Schnorr Aug 16 '13 at 13:05
  • Ok. I take it you don't get header reuse from the table view then? I got it to work by not using the built-in labels and added my own, that way you can still reuse the headers. Took a while to get it working though. – Accatyyc Aug 16 '13 at 13:58
  • I have them cached anyway to do some nice animations when the screen rotates, so I wouldn't want to reuse them anyway. – Christian Schnorr Aug 16 '13 at 14:57

1 Answers1

3

It seems an attempt to modify the frame of backgroundView or contentView not only causes an infinite loop, it will ignore any values you set to their frames, rendering their existence fairly useless. I've reverted to using the backgroundView and contentView as dumb containers for my own custom subviews with their own background visuals and layout properties. :S

epologee
  • 11,229
  • 11
  • 68
  • 104