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).
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.
Related
I am setting up a login page in my app and decided to add a navigation bar to display an image/logo. However, after I added this navigation bar and ran my code in the simulator the content of my view is being pushed down. I have attached pictures to show the difference between the interface builder and the simulator. All of my constraints are related to the super view and my view encompasses the whole screen.
interface builder screenshot
simulator screenshot
follow the steps :-
add a new view inside the main view
insert all elements in that 2nd view
give the constrain to 2nd view (if possible then give static height and width)
give constrain to all elements inside of 2nd view
must give 2nd view center x,y constrains
i hope it will work for you ...!
For anyone who comes back here later:
All of the above answers work in their cases, however the issue for me was that I had "under opaque bars" in my storyboard unchecked which caused the view to display lower than it should.
I have a UITableView has a subview of a UIView and I've added a toolbar on top of the UITableView so it should look like this:
However when I actually run it, it looks like this:
So for some reason the UIToolBar isn't showing up. I really don't know why, is anybody able to figure this one out? Thanks in advance.
EDIT: I've changed the simulated metrics like suggested and it still does not show up:
EDIT2: Here is a list of objects as requested by Raixer.
Alright. I have a similar setup in my app so I will show you what I did.
I setup a tab bar controller with navigation controllers in each tab (this gives me the navigation bar automatically that is why I use it). If you notice the View on the first tab is being loaded from another nib (that is what I am assuming you are doing). I did this by changing the view's class to my own view controller and then setting the name of the NIB file to load in the Inspector like this:
(source: minus.com)
Then in my other nib file I only have this:
I hope this helps.
That's because you configured your nib file without counting with the height of the Tab bar.
The toolbar's height is 49 pixels. So when the view appears all your elements are moved 49 pixels up.
You should got to IB, open your View, go to Attributes Inspector, and in simulated metrics select Tab bar for Bottom Bar.
I doubt you will succeed with this approch. UITableViewController is very picky about adding subviews to its UITableView. However, you can have your UITableView handled by a standard UIViewController (just let IB point to a custom class inheritng from UIViewController). Add the table view to the controller's view as a subview and add the toolbar to the outer view.
Then you should be able to add subviews. UITableViewController gives you some convinience and functionality. If you can live without, UIViewController is no disadvantage. If you can't, you'll have to implement it yourself.
Another alternative to get the toolbar: put your table into a UINavigationController. That one comes with a toolbar (on top).
I placed a UISegmentedControl programmatically on the screen (stand-alone, not as part of a navigation bar) and set its autoresizingMask to UIViewAutoresizingFlexibleLeftMargin because I want it to stick to the right.
However, when I rotate the screen the control stays in its original position and does not move to the right (or anywhere else for that matter).
I also tried all other possible values (and some combinations) for the autoresizingMask, but the thing doesn't move at all.
Other elements on the screen with the same setting move correctly.
I do not have a XIB for this view controller, but I tried to place a similar segmented control temporarily in another XIB, and when I set the struts correctly it did move as expected.
What am I doing wrong?
In your view controller's viewDidLoad method place the following log statement:
NSLog(#"%#", [self.view recursiveDescription]);
This will log out your view controller's view hierarchy. If it's not clear from the log where the issue is, then please add the log to your question so we can help further.
I've created a simple application with a single view controller and removed the status bar so I can use the full height of the screen. The view controller's xib file loads perfectly well, displaying a backdrop image very nicely. I then added a custom view object which will be handling certain graphical tasks directly for me, and asked it to initialize itself with the custom view's frame rectangle. I did this in the 'viewDidLoad' method for the view controller. For some strange reason though, the view controller is reporting its frame rectangle as if the status bar were still visible, despite the fact that I hide it before creating the view controller. Can someone explain why, and maybe suggest a workaround?
-Ash
Oops, it's always the simple things isn't it? I just forgot this command:
viewHolder.wantsFullScreenLayout = YES;
Hey everyone, running into a bit of an issue,
I have created all my views through IB, with the main window having a NavigationController, and a TabBarController which loads a TableViewController in its first tab.
The problem happens when i use the searchbarcontroller in the navigation controller, everything works fine with the exception that when the navigation bar at the top disappears, the table expands too high, and i can't figure out what im doing wrong.
Attached is an image of what im referring to, any help would be greatly appreciated.
alt text http://img263.imageshack.us/img263/4706/picture1ot.png
Some more information:
i have my MainWindow with a UINavigationController, and a UITabBarController. On the first Tab, i have it loading another nib "AVN_TableController" which is a UITableViewController nib, with the Searchbar delegate.
If you've set your view sizes correctly in Interface Builder and are using the "Simulated Interface Elements" to cause the status bar, navigation bar, and tab bar to display, it should work correctly. If not, then what comes to mind is this issue where displaying an action sheet has it's tappable rectangle offset by the height of the tab bar because it is added to the wrong view. Not sure if that would apply here, but it's at least something to consider.
I ended up going the route of creating my own tabbarcontroller, as that was causing the issue.