In my app, I have a collection view controller that is accessible by a modal type segue. What I am want is to have a top bar on the collection view controller. However, when I set a top bar in attributes tab of the collection view controller, it shows on the storyboard but not in simulator?
I think that What you are looking for is a UICollectionReusableView.
You should use UINavigationController.
If you're not using it, you could also add a UIToolbar.
That Storyboard section only sets the appearance in case you're using UINavigationController.
Related
See the image below. I've Tab Bar Controller. I've embedded Table view in Navigation Controller. I've further child Table view & two UI views.
As you can see Navigation Bar appears for some view while it doesn't appear for other. Why is this? How to fix it.
I've not added any code, just trying it in storyboard.
It looks like it is showing the navigation bar just not the title of the other view controllers. That's where you are seeing <Back. If you set the Title field on the view controller, you should see the title in that same area.
I have a view controller with a table view and a tab bar controller. I perform a segue when one of the cells is tapped in the didSelectRow method. I then pass the data in prepareForSegue. The segue is set up in the storyboard from the view controller to the tab bar and its kind is "Show".
When the tab bar controller is displayed (well, one of its view controllers), the content is at the very top of the view. The problem is fixed after I switch tab bars and then go back to the original tab bar. Any way to fix this?
Are you using interface builder?
Open storyboard where you defined this view controller.
Then in Attributes Inspector DESELECT the Extend Edges Under Top Bars property.
Alternatively you can make your view snap to the Top Layout Guide instead of the root view itself.
Back when I first created the foundational layout for the app I'm currently working on in Storyboard, I did it in two steps:
Selected my View Controller and used Editor->Embed In->Navigation Controller.
Selected my View Controller again and used Editor->Embed In->Tab Bar Controller.
This was the resulting layout:
Question 1: Why do these steps create such an odd layout?
In this weird layout that seems to imply that the Navigation Controller is attached to the Tab Bar Controller as its parent, the only way I can get navigation items to display in the app (in the view controlled by the View Controller on the right) is by placing them in the nav bar of the Tab Bar Controller scene.
However, this creates various issues, including not being able to create an IBOutlet in my View Controller file for a custom view I drag into the title view slot in the Tab Bar Controller scene. Meanwhile, dragging anything into the navigation bar in the View Controller scene just makes it not appear in the app when it runs.
Question 2: How can I fix this layout so that I can control-drag from navigation items into my View Controller file? Or is everything actually correct, and I'm just trying to force something I shouldn't? (My intention here is to be able to set the custom title view's text in my View Controller code.)
Its obvious, if you want to embed MyViewController to NavigationController then you need to change your second step and need to embed NavigationController to Tab Bar Controller.
Selected MyViewController and used Editor->Embed In->Navigation Controller.
Selected NavigationController Embed with MyViewController and used Editor->Embed In->Tab Bar Controller.
It should look like this.
Note: You need to embed MyViewController to navigationController only if you want to perform push operation on this TabBarItem means with MyViewController other wise simply embed MyViewController to TabBarController no need to embed it with NavigationController.
I have have a view controller that is embedded in a UINavigationController and I want to segue to another view controller that is also embedded in a different UINavigationController. If I try to use a push segue, I get an error saying that I can't push a UINavigationController. However, I don't think using a modal segue is appropriate. How should I go about this?
How should I go about this?
You should use a single navigation controller.
the problem is that I want different bar button items for each view controller and they won't change
Each view controller can set up the bar buttons however it likes. Take a look at UINavigationItem. Each view controller has a navigation item, and the navigation item has various properties such as leftBarButtonItems and rightBarButtonItems that you can use to set the buttons.
I have a UIViewController which i have embedded in a Navigation controller using:
Editor->Embed In->Navigation Controller
Now i want to get the upper bar height for some calculations but i cant ctrl+drag
anything to use the needed property.
How can this be done?
The "upper bar" is the UINavigationController's navigationBar. And thus your view controller has a reference to it.
If you are trying to do auto layout, stay inside the embedded view controller and pin to the Top Layout Guide. That is what it is for.