0

I have setBackgroundImage in viewDidLayoutSubviews. It calls viewDidLayoutSubviews infinitely. As a result memory is increased with app termination. What am I doing wrong? It happens only in iPhone 5s and the same code works fine in iPad Air and iPhone 4s.

[_hosStartDateBtn setBackgroundImage:[UIImage imageNamed:@"cal23.png"] forState:UIControlStateNormal];
//_hosStartDateBtn is a button added programatically in viewDidLayoutSubviews
Kampai
  • 22,848
  • 21
  • 95
  • 95
  • Why not try moving the setBackgroundImage code outside the viewDidLayoutSubviews ? – Zhang Nov 17 '14 at 06:54
  • yes it works if i add the same code in viewWillAppear..what is the issue if i put it in viewDidLayoutSubviews? – puneetha koopadira Nov 17 '14 at 07:01
  • don't add _hosStartDateBtn to view in viewDidLayoutSubviews – Shankar BS Nov 17 '14 at 07:01
  • 2
    Probably what @Shan said. I'm guessing when you addSubview inside viewDidLayoutSubviews(), it triggers another viewDidLayoutSubviews() call, resulting in an infinite loop as you mentioned. Probably not wise to put those code in viewDidLayoutSubviews. – Zhang Nov 17 '14 at 07:04
  • OK..I have added my code in ViewWillAppear..it is working fine but scroll content size is not getting set properly in ViewWillAppear but works fine in viewDidLayoutSubviews – puneetha koopadira Nov 17 '14 at 07:17

0 Answers0