12

Really strange behaviour here. I've got a view with a scroll view inside, which contains my interface.

In my viewDidLoad, I set the frame of my scrollView to have an origin of 0,0.

I log the origin at the end of my viewDidLoad, and it's 0. However, at the start of my viewWillAppear, the origin is -20. Does anyone know what kind of method could get called that would do this?

Thanks in advance

Alex Coplan
  • 13,211
  • 19
  • 77
  • 138
  • Can you post the line where you log the origin? it's funny that the status bar is 20px, but that doesn't explain the minus sign. – Jano Jul 25 '11 at 20:21

3 Answers3

32

You are correct with the current method precedence:

-(void)loadView;
-(void)viewDidLoad;
-(void)viewWillAppear;
-(void)viewDidAppear;

Is there perhaps a rotation call or some other method in the way, such as didRotateToInterfaceOrientation; for example? Also, is this scroll view part of a controller that's loaded from a nib file?

Luke
  • 11,426
  • 43
  • 60
  • 69
  • yes... I think it might be to do with the nib... how could I find that out? – Alex Coplan Jul 25 '11 at 19:44
  • Are you using the -(void)awakeFromNib: method? If not, throw it in and consider moving some calculations in there.... I forgot how this method fits in with my list above. – Luke Jul 25 '11 at 21:39
6

If you want to find out what it could be, you can try registering your view for key value observing, as described here: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html

You can register to listen for changes to the frame property, and then set a breakpoint in the observe method which should let you see exactly what the stacktrace is for when your origin is set to the strange value.

Kevlar
  • 8,804
  • 9
  • 55
  • 81
2

20 pixel discrepancies and nib files always seem to be woe, but with Interface Builder and status bars. Are you setting up the nib with the same status-bar state as what your using in your app?

If you've hidden your status bar in your app, have you done the same in Interface Builder?

Benjamin Mayo
  • 6,649
  • 2
  • 26
  • 25