Does the iOS tabbar/toolbar support buttons/labels/images? - ios

I am looking to have a UITableViewController that has a TableView with 2 sections and a tabbar/toolbar that holds two buttons, 1 share button and the other is a button that pushes a view controller. The table view should be underneath the tabbar/toolbar (or the frame should not go under the toolbar/tabbar). If toolbar/tabbar is not possible having a image/button I was thinking of making a view to have as a subview.
Here is what it should look like:
If anyone has any suggestions or ideas of how to go about this, any guidance would be appreciated. Thanks in advance!

First of all you want a UIToolbar not a UITabBar.
Secondly the only kind of element UIToolbar can hold is UIBarItem, specifically you are interested in its concrete subclass UIBarButtonItem.
UIBarButtonItem can either be a system item or hold a custom UIView. Since UIButton and UILabel are all subclasses of UIView you can place them inside a UIBarButtonItem and add this item to the toolbar.

Yes,you drag a tabbar to your viewcontroller, an then drag buttons or other things inside of that tabbar.

Related

Swift: Add segmented controller to a navigation bar, and keep the title + nav buttons

I'd like to add a segmented controller to a navigation bar, below the title.
At the moment, I've got a storyboard UITableViewController with a CoreData-sourced dynamic table, embedded in a UINavigationController. I'd like the UISegmentedController to differentiate the sorting of the table.
There seems to be obj-C solutions available stackoverflow.com/questions/29480433/ and stackoverflow.com/questions/18813563, but I'm looking for a Swift solution, that resembles the native apps. I've also tried putting the segmented controller into a table cell with little success (can't get the action recognised). I'd prefer not to abandon the table view controller.
Any suggestions?
I replaced the UITableViewController with a UIViewController and UITableView, then added the UISegmentedController to a UIToolBar positioned below the UINavigationBar.
I used removeShadow for the navbar, then clipsToBounds for the toolbar. I also added another View to simulate the bottom shadow on the toolbar (because I couldn't get the toolbar shadow/background position function to work).

UINavigationBar inside UITableViewController

I have some static cells that I want to display, so I have a UITableViewController. There is also a NavigationBar in this scene that contains some buttons at the top. The setup looks like this:
If I had a UIViewController that contained a UITableView in it, the setup would look like:
So, the question is:
Why does the Navigation Bar have to be embedded inside the UITableView when using a UITableViewController? (I have tried putting it elsewhere but IB won't let me)
I know that UITableView is a subclass of UIView, but is it OK that the top level element in the hierarchy is not a View (but a TableView)?
Thanks.
You shouldn't be placing your UINavigationBar in your UITableView. You should be putting your UITableViewController in a UINavigationController, because that will provide a UINavigationBar for you.
So if you select your UITableViewController in the storyboard, you can choose Embed In -> Navigation Controller from the Editor menu. This would be the proper way to do it.
There are two ways to use a UINavigationBar in iOS:
Embedded inside a UINavigationController (recommended)
As a standalone object
For your particular situation, I'd recommend that you put your UITableViewController as the rootViewController of a UINavigationController. That way you automatically get a navigation bar which you can customize according to your needs. In a typical user experience, when you tap some of your table view rows a new view controller will be pushed onto the navigation stack, so you'll probably end up needing a navigation controller anyway.
What if you decide to use a navigation bar as a standalone object? This is perfectly fine, you can use it inside a view hierarchy as an ordinary UIView, but you'll need to create another object that implements the UINavigationBarDelegate protocol and set it as the delegate property of your navigation bar. If you use a UINavigationController the delegate is already set and configured for you. You also need to add/remove navigation items (instances of UINavigationItem) to your navigation bar by using the pushNavigationItem:animated: and popNavigationItemAnimated: methods.
And about your question on the view hierarchy, you can use a UITableView anywhere a UIView is required. The only caveat is that a UITableView is a view hierarchy on its own and that may restrict your layout a little bit.
The way a UITableViewController works, is its root view is a UITableView. So there is no way to put the UINavigationBar anywhere other than in the UITableView.
I tend never to use a UITableViewController as it doesn't really give you much.
If you particularly want to use the UITableViewController, I don't believe that there is any real problem in having the navigation bar within the table view. You just need to make sure that you set the contentInset on the table view such that the navigation bar doesn't block the content. Though it seems a bit backward to do it this way.
My recommendation would be to just use a normal UIViewController with a navigation bar and a table view.
If you actually need functional navigation, you need to put your UITableViewController within a UINavigationController.
Hope this helps :)
Let me know if anything is still unclear.

Changing toolbar item from toolbar subclass does not update toolbar immediately

I have a subclass of UIToolbar. I created it because I have the same toolbar on multiple pages(UIViewControllers). I took UIToolbar on my UIViewControllers (I am using storyboards) and assign this subclass to the UIToolbar class.
Also each item on that toolbar is created with a custom view (UIButton). When I change one of the items from its subclass, it's not reflecting immediately on the toolbar. I have to go to another screen and come back to view the updated result.
Is there any way to update immediately? Thanks.

Toolbar on top of tableview

I'm trying to achieve to display a toolbar on top of a tableview. I'm working for iOS5 with storyboards I need a toolbar because it needs to be customized in a way a navigation controller does not allow me to do.
The following image shows what I want to achieve:
The left and right white arrows are what I think I can't achieve with the use of a navigationcontroller. Right now I got to display everything (The screenshot is from the iphone simulator), but my problem is that the toolbar scrolls with the table, and I would like it to stay on top. I think this is because of the way I wired up things in the storyboard. Next image shows a snapshot of what the view looks like in storyboard:
The controller is a subclass of UITableViewController. The toolbar is inside the tableview because the StoryBoard editor did not allow me to put it anywhere else.
I've tried to create a new generic view controller from the storyboard, drop a toolbar and a tableview and then set the type of the controller to my custom UITableViewController. Then the storyboard does allow me to have the toolbar on top and then the tableview. The problem is that when I run this version the program terminates with a
libc++abi.dylib: terminate called throwing an exception
So right now I don't know what to do. Is there any way I can make the toolbar stay on top? Can I accomplish my objective with a navigationcontroller (using storyboards) and thus make things easier?
Any help will be appreciated. Thanks.
Depending on how you want to behave, stationary or scrolling. You can add a subview to the
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 44, 320, toolbarHeight)];
[self.navigationController.navigationBar addSubview:myView]
In 'myView' you can add all the buttons you need. Then you can leave the first cell empty.
Instead of using a TableViewController I would start with a simple ViewController then add a TableView and a Toolbar. It's going to take more code but I don't see how any of the "template" controllers will let you do what you want.

Adding a toolbar to a navigation controller

I am completely new to ios development and I am only interested in developing for ios5.
I have an app with some scenes, they are mostly tableviews. I also use a navigation controller
I however need to add some status text and buttons that are always visible in all scenes and thought that a toolbar added to the navigation controller should do the trick.
so i thought that i should only have to drag out a toolbar in storyboard to the navigation controller, but it does not stick there. I can add it to the bar underneath with first responder and navigation controller but that does not help me (small icons).
I can also not add it to my table view (but if i drag out a plain view I can add it there)
do I have to make my own custom navigation class that the navigate view uses and then programatically add my toolbar?
Had the same question recently. Check Attributes Inspector in your ViewController's properties in storyboard. There you can define a Bottom Bar.
Well, inside the UINavigationController, you should have something... A UIViewController for instance. You can easily add a UIToolBar by dragging the object inside the UIView of the UIViewController. What might being happening is that as the root view you have the UITableView, in that case I think you can't do that. But to better understand, just take a small print screen of your StoryBoard.
If you zoom up to 100% on the storyboard it should drag.

Resources