ios rightBarButtonItem - objective-c

I have a UITabBarController which is the second item inside a UINavigationController.
Each item within the UITabBarController is a sub class of UIViewController. How can I create a button that appears at the top right of the navigationBar and changes depending on which tab is selected.
I am using storyboards, just in case there is a gui way of achieving this.

Implement the UITabBarControllerDelegate method tabBarController:didSelectViewController: and then depending on what view controller was selected set the rightBarButtonItem of your UINavigationController to show whatever you want it to show.

Related

Add a UINavigationBar and UIToolbar to modal UITableViewController

I'm creating an app that has a similar layout as the Apple Contacts app. I have created a UITableViewController and embedded it in a UINavigationController using a Storyboard. I then have an add button that opens a UITableViewController in a modal view. I have added a top bar to this view using the storyboard and it works pretty good. The problem is that it scrolls away when you scroll in the table. It should stick to the top.
Do I need to embed this modal UITableViewController in a UINavigationController as well to get the "sticky top bar"?
What's the preferred way of doing this? Just embed using the storyboard or just create one "on the fly" in the prepareForSegue method?
EDIT
I ended up just embedding the modal UITableViewControllers in UINavigationControllers using Storyboard.
Yes, you do need a UINavigationController that contains the UITableViewController to get what you aim for.
Personally, I would prefer creating it "on the fly" as you call it. But that is a matter of taste.
The way to do it in the storyboard is to have your modal view controller be a UIViewController rather than a UITableViewController. Add a view controller, then drag in a tool bar, and position it at the top. Then add a table view to take up the rest of the space below the tool bar. This will work correctly without scrolling with the table view.

Selection of UITabBarItem loading corresponding view

I have a UIViewController named "RootViewController" which contains a UITableView and a UITabBar (2 TabBarItems - Favorites and More).
When the View is being displayed, the TableView and TabBar are visible. Now I want to load an additional view when pressing the other TabBarItem (More). And backwards, but the tabbar should be available. (User can press Favorites)
How can this be done?
BR,
mybecks
If you want the UITabBar to be visible on more than one screen you should use a UITabBarController. That controller should hold your different UIViewController.
It's wheel explain in the documentation on how to implement that controller.

UIView controller containing toolbar and UITabBarController

I'm currently creating an ipad application.
the idea is to have a toolbar at the top and a tabbar at the bottom.
The toolbar has to be visible on all tabs, so it won't disappear.
I was thinking about having a UIViewController as the main view and put the tool bar in there.
Then adding the uitabbarcontroller to that main view controller, but i'm not sure how to do that.
At the moment i have my tabbarcontroller as the main view and added the toolbar to every tab.
Can anyone help?
Thanks
The Tab Bar Controller should be at the root. What you can do is create a method that returns a propertly configured toolbar & add it to each of the view controller's viewDidLoad (either by using a category method, inheriting a common UIViewController subclass, or simply via a C-style factory method.
This way your hierarchy isn't flipped, and the tab bar is at the root like it should be.

How to Notify RootViewController of View Changes

I have added a UIButton to a toolbar that is only accessible via the RootViewController (which has a navigation bar and toolbar) of my app. When navigating to another view, I hide the UIButton, but when I go back to the initial screen (a map view) the UIButton remains hidden and I must unhide it. Since it is the RootViewController I am doing this in, viewWillAppear is not called, so I cannot use that method.
I am wondering if there is any way the RootViewController knows when a view is being popped off the navigationController stack, if so, how would you suggest I check for this? Is there any way you would recommend implementing this?
Thanks in advance!
if your app using UINavigationController for navigation then viewWillAppear will obviously called

UINavgationController and UITabBarController together

I am trying to create a view with a TableView in the center, NavigationBar on top, and a TabBar with 5 items. The TabBarItems will be attached to 5 different modal views. And the tableview can select an item and "navigate" to another tableview or detail view.
Following the Apple doc, I tried to create a NavigationController in a TabBarController in IB, but failed. I read all the posting regarding to this topic, and they all described a NavigationController inside one of the TabBarItem. But that is not what I want. The TabBarController and NavigationController are separate controller doing separate thing in the same view.
So I start wondering maybe it is a design issue. I should just use a NavigationController and add the TabBar as objects and not controller in the view.
Am I going the right track or is there a better way to combine NavigationController and TabBarController in IB to do the job that I want. Am I making sense?
If the tab bar is actually being used as a tab bar, it sounds like you want 5 navigation controllers, one for each tab.
If the tab bar is being used as a toolbar to hold buttons that bring up modal view controllers, push views onto the navigation controller, or other actions besides what a tab bar is intended for, use a UIToolbar instead. UINavigationController actually has toolbar support built in, just set its toolbarHidden property to NO and set the toolbarItems property on each view controller that can go inside the navigation controller to an array of appropriate UIBarButtonItems.