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.
Related
I'm having trouble getting a UIToolbar to appear at the bottom of the screen when my app loads. Regardless of how I position the UIToolbar and regardless of the constraints that I have put on the bar, it always appears in the middle of the screen. I have my navigation bar situated correctly, and I've never had trouble situating UI elements in IB before (although I'm new to iOS programming). Any ideas on how to make sure the toolbar stays in place? Thanks.
You're probably not playing the game correctly with UINavigationController. See:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/
Displaying a Navigation Toolbar
A navigation controller object manages
an optional toolbar in its view hierarchy. When displayed, this
toolbar obtains its current set of items from the toolbarItems
property of the active view controller. When the active view
controller changes, the navigation controller updates the toolbar
items to match the new view controller, animating the new items into
position when appropriate.
The navigation toolbar is hidden by default but you can show it for
your navigation interface by calling the setToolbarHidden:animated:
method of your navigation controller object. If not all of your view
controllers support toolbar items, your delegate object can call this
method to toggle the visibility of the toolbar during subsequent push
and pop operations. To use a custom UIToolbar subclass, use the
initWithNavigationBarClass:toolbarClass: method to initialize the
navigation controller.
EDIT to include answer to question in comments:
No code needs to be written to do all this. You can set "Shows Toolbar" in the Attributes Inspector of your Navigation VC. You can then drag individual UIBarButtonItems onto particular VCs (on which a toolbar will suddenly appear) and do the usual outlets and actions with them.
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.
I have created a subclass of UIToolbar. And setting toolbar items from that class. On ViewController, i took a toolbar and assign it a class subclass of UIToolbar. Its showing toolbar items on it.
The problem is that, when i update toolbar items its not showing on viewController. When i go to another view and come to this view its showing updated toolbar items.
I need an immediate refresh of toolbar items on that viewController.
In the viewController that contains your UIToolbar, call "[self.view setNeedsLayout]" (or even just [self.toolbar setNeedsLayout]) to force re-drawing of the graphics context.
On a different note, though: You should not need to subclass UIToolbar to just set the toolbar items. Create a UIToolbar and set its items array by calling [self.myToolbar setItems:#[item1, item2, ...]]
I am following a post here showing how to add a custom center tab bar item.
What's the best way of adding a custom centre button to a tab bar?
My only question is where should the code be put? I am using storyboards and right now I have it placed in viewwillappear for my default view that is shown. Should this go in a more generic or global area?
Create a subclass of the UITabBarController, say MyTabBarController.
In the storyboard, drag the standard UITabBarController into the scene, and change its class type to MyTabBarController.
In the MyTabBarController, insert the code within its viewDidLoad method.
If you put it within the viewwillappear method, it will be added multiple times since the viewwillappear will be called every time the tabbarcontroller is displayed.
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.