0

In my iPhone application, which is based on a NavigationController, I have some elements a, b, c subviews of another view X. When I push the controller to get this view, on viewWillAppear, I adjust the size and position of a, b, and c according to the size of X in order to properly handle device orientation. The problem is that the size of X is being changed after viewWillAppear has been called. I subclassed X and wrote a setFrame method in order to set a breakpoint and try to find the cause. Below are links to images (I could not post the image directly due to lack of points) showing the break at viewWillAppear, and the break at setFrame after viewWillAppear with the callstack. I need help to find out why the size of X is being changed this way. Thanks.

At viewWillAppear: http://img718.imageshack.us/img718/9898/viewwillappearbreak.th.png

After viewWillAppear in break at subclassed setFrame: http://img703.imageshack.us/img703/7995/afterviewwillappear.th.png

Thanks in advance. ( I hope the images will show up correctly).

DDRider62
  • 753
  • 6
  • 17
  • What does your implementation of viewWillAppear and viewDidAppear look like? Code snippet would be nice. In particular, when do you call [super viewWillAppear] and [super viewDidAppear] from your own implementations? – occulus Oct 22 '11 at 20:00
  • Also, have you considered using autoresize springs in your views to have the components resize and/or position themselves correctly when orientation changes? Also just double checking what autoresize behaviour is set up might be a good idea. – occulus Oct 22 '11 at 20:02
  • Btw, this could relate to layoutSubviews being called, in which case the following answer might be useful: http://stackoverflow.com/questions/728372/when-is-layoutsubviews-called The answer at the top has a link to a useful blog post relating to when layoutSubviews is called. – occulus Oct 22 '11 at 20:04
  • Actually the size adjustment I am doing on orientation change is more adjusting the scale of an image to the available view space, so the autoresize springs were not enough. But, a good pointer anyway. Thanks. – DDRider62 Oct 23 '11 at 08:24

1 Answers1

0

Thanks for all the responses with the limited information I provided. I finally found the cause of the problem. My nib file included a toolbar (which I guess is a bad thing to do if you are using a navigation controller) and I was also calling

setToolbarHidden: NO

on my Navigation Controller. I'm new to iPhone programming, and thought that the toolbar in the nib file would somehow be shown as the navigation view toolbar. It seems this is not the case. My understanding of why the problem was happening, is:

  • The view got loaded with a toolbar from the nib, and the navigation controller had a visible toolbar, so my X view height was 328. (the height of 2 toolbars were being subtracted when adjusting to the screen size. the one from the navigator controller and the one in the view).
  • After viewWillAppear, the navigation controller code apparently found the 2 toolbars, so it decided to hide the one in the navigation controller, increasing my X view height by 44 (to 372).

I removed the toolbar from the nib file, and added the toolbar items to the navigation controller toolbar by calling

setToolbarItems

The height of the frame remained unchanged after viewWillAppear.

Thanks for the responses. I hope this comments will benefit someone else facing the same issue.

DDRider62
  • 753
  • 6
  • 17