Toolbar on top of tableview - uitableview

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.

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).

How do I make a now playing bar like in media player apps in iOS with XCode?

I am making a media player app. I have UITableViewControllers that are embedded in Navigation Controller. I would like to somehow make a view that would overlay potentially multiple (2?) of these tableviewcontrollers (one that shows the user's playlists, and the next would show the tracks in the playlist), but only at the bottom, like a now playing bar in (e.g.) Spotify's iOS app (as in the left bottom side of this
or as in this
I have tried to drag a Container View into my Navigation controller (in which my TableViewCell is embedded), but it won't let me drop it there.
It looks like I can drag the Container View into my TableView, but then how would it remain there when i navigate between tableviews?
Trying to follow #Rintaro's suggestion, but I'm a little new to XCode. How did you do this? So I made a single view application, i added a container view to the first VC, it's imm drawing it somewhere else in the storyboard, but i can't figure out how to tell that view that it's a navigation controller. also, as soon as i add a second container to the first VC and tried to size it, the first container disappears! It is still listed in the hierarchy on the left, and still has an arrow pointing out of it, but the view controller that was added and was being pointed to is also invisible?!
UPDATE: This works very well, but it has a problem with orientation changes. how can i make this work in both orientations? (I hypothesize that it currently positions the "nowplaying view" off screen when the orientation changes).
Basically, view hierarchy like that is constructed like this:
Using two "Container View" in initial view controller, one for Navigation Controller, one for "Now Playing Bar" view controller.
ADDED:
"Main Container View Controller" would be your own UIViewController subclass. It will have responsibility to show/hide "Now Playing Bar".
Workaround for Interface Builder strange behaviors.
You can set Auto Layout constraints like following. Maybe you might want to select the view from the left menu.
Note that, you should uncheck Constrain to margins check box.
Container View for Navigation Controller:
Container View for Now Playing Bar Controller:
And then, Update Frames from the menu:
If you are manually placing any buttons with absolute coordinates, make sure that you update the coordinates of them when the rotation is changed.
Obviously you need to create a custom UIView class, where you will show this menu. And when you will create it, add it to your view just like here:
float y = ROOTVC.view.frame.size.height - 49;
[self setFrame:CGRectMake(0, y, 320, 49)];
[ROOTVC.view addSubview:self];
[ROOTVC.view bringSubviewToFront:self];
I would simply add a nowPlayingView to the appDelegate.window and adjust either:
The window.rootController.view frame to avoid overlapping the nowPlayingView.
If window.rootController.view is a UIScrollView, adjust its contentInset.bottom to avoid overlapping the nowPlayingView. You can also use transparency/translucency with this solution.
Add a dummy toolbar to the controller that will get covered by the nowPlayingView.
If your window.rootController is a UINavigationController, then you have to probably do the above fore each controller you push. The nowPlayingView will stay unchanged on top.

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

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.

XCode 5 storyboard toolbar

In XCode 5 storyboard (and maybe previous versions) I can drag a UIToolbar to the black area that shows underneath the view, so I have a view, first responder, toolbar and exit button.
But I can't seem to find any documentation that states the purpose of adding a toolbar there rather than in the view itself.
Does anyone know what this is for?
Thanks,
AJ
You can drag anything you like in there really, not just a toolbar.
The purpose is to have those objects instantiated along with the main view so that they are accessible from the ViewController (hook them up via IBOutlets).

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