ViewController's content is pushed down by navigation controller - swift

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.

Related

Load a view controller created inside a storyboard as a subview (into a part of the screen) of another view controller

I am currently developing as app for iPad. And I need to create a tabbar. The problem is that, for design purposes, I need the tabbar to be on the top half of the screen and not on the bottom as it is on the default tabbar controller.
Once the tabbar is on top I want that when a button is touched, the subview bellow the tab is changed. Furthermore, the subview that should be loaded was alson designed inside the storyboard. The following sketch shows what I want it to look like:
On my research I found a solution (here) for putting the tabbar on top. Now my problem is on loading a subview bellow it.
I tried it with [self.view addsubview:theNameOfTheViewCreatedINStoryboad.view] but the application simply hangs when I press the button.
I think that is because I am not specifying anywhere what should be the dimension of the new view or where on the scree should it be placed. The reason for that is because I do not know where it should be done.
Can anyone give me some lights on this matter? Is the referred approach the best one for putting a tabbar on top? How can I solve the subview problem?
Glad to see you are using a toolBar and not a tabBar. Even better would be to create a custom content view controller.
You should be looking into using containment:
UIViewController containment
How does View Controller Containment work in iOS 5?
positioning UIViewController containment children
check out the docs

How to access additional UI element in Interface Builder (Storyboard)?

I can drag & drop a ui element from the "objects-selection" and add it to my current scene (marked red in the picture) but how can I edit it? Xcode doesn't show it in the editor, nor does double clicking the element make it visible.
Depending on what you want to do with it.... Perhaps you could make it a subview of the current view in order to configure it and then remove it from its superview in code if you don't want it to appear.
Based on the hierarchy picture you provided, you are aware that the view you added is not part of the view controller's view hierarchy, correct? You would need to set the view controller's view property to this view in order to see it. If your intention was to add this as a subview of the current view, you should drag the view from the object repository directly onto the view. Alternatively, you can drag it from the View Controller Scene on the left and associate it as a sub view that way.
Also, note that when you pull the view onto the canvas, it's white. It may have been there and you just didn't see it if you had originally made it a subview of the current view.
I suppose the right way would be to add the extra view to the view controller's view, and have it hidden. Yes, it is going to be a pain to configure views this way. On the other hand this way those views do got the proper memory treatment and can get unloaded under memory pressure.

View size changing after viewWillAppear

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.

How do you set autosizing to flex in Interface Builder?

I have an iPhone project that I started as a Windows-based app and another View-based app. The Window app has a view which I added and I want to make the view fit within the window. In the View app the view is set to stretch.
Here is what it looks like when it is off.
(source: smallsharptools.com)
And here is when it is on.
http://www.smallsharptools.com/downloads/Stackoverflow/autosizing-on.png
I want to click in the middle of the Autosizing box but it does not do anything. What do I have to do in Interface Builder to make the View in a NIB to flex/stretch the view?
Usually when a view is locked down like that, it means that you have some simulated UI elements in place (like a fake nav bar, tab bar, or status bar). Select the top level view and go to the first tab of the inspector to see if any of those are turned on (you'd also see them on the view of course).
When they are all gone then you can change any of the resizing handles you like.
The view that is provided by default has this kind of limitation but you can overcome this by adding another view (you should delete the first view) to your xib and making this view the view of your file's owner. Besides this you would also have to change the height of this new view to 480 pxls.
Hope this helps.
Thanks,
Madhup

UISearchDisplayController,UINavigationController,UITabBarController Woes

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.