UITabbarViewController: Use StoryboardReferences - swift

To have each tab content in it's own Storyboar I use storyboard references and configure the title and image in my viewcontroller.
I set the image and the title inside the viewDidLoad method in each viewcontroller. This has the problem that the TabbarItem is not displayed until I tab it, beacause the viewcontrollers are lazy loaded an not when the tabbbarController is loaded.
How can I improve this?

I would suggest you to take UINavigationController before your UIViewController's reference and make root view of that UINavigationController. By this way it will give you a tabbar item to configure in UINavigationController in storyboard.

Related

Show UITabBar on UIViewControllers that are not part of the UITabBar?

I have an iOS app written in Swift with UITabBarController with 5 UIViewControllers. Now, I have a bunch of UIViewControllers that are not part of the UITabBarController. I'd like to be able to show that same tabbar but I have no idea how to do that. Any clue?
More details: This is one of the View Controllers that the tabbar has. I use storyboard references and split my view controllers into separate more manageable storyboards.
So, the big picture:
There's no initial ViewController since I use storyboardId to get to the initial Navigation Controller. From there we have a ViewController embedded in the same Navigation controller. In that ViewController, there are 2 Container views - one of the size of the bottom ViewController that contains the "hamburger" button that toggles the other Container View which has an embedded UITableView in. When a specific cell is selected it should go to Profile ViewController that's not even in the same storyboard. The segue is set to be Push. Either way, doesn't show the UITabBar on the Profile ViewController
how you doing?
I don't know if I understood, but you are trying to show tabbar after going to another screen, right? If the answer is 'yes', try to change your segue to show(e.g. push).
-----Edit-----
You can do with two ways:
Presenting Modally -> using Current Context
Use push(e.g.) with a navigation view controller, you can also hide the navigation bar if you go to Navigation controller -> Attributes inspector -> Navigation Controller -> Uncheck Shows Navigation Bar
Hope now it works!
Best regards

Changing the BadgeValue from a UISplitViewController 's detail view

The main view of my iPad app is a TabBarController. Each Tab contains a UISplitViewController.
The UISplitViewController contains UINavigationControllers.
How do I change the tab's BadgeValue from a ViewController located within a UISplitViewController.
I've tried setting the TabBarItem property of the ViewController but there is no effect.
Strangely the UIViewContoller's NavigationController and SplitViewController property's are null even though the UIViewContoller is in a NavigationController which is in a SplitViewController .
Summary: The Heirarchy looks like this:
tabbar
splitview
navigation
viewcontroller
Found it.
A TabBarController's tabbar is accessed by the direct child, in this case the SplitController.
Because the SplitController doesn't get loaded until the tab is pressed, you have to set the badge when you create the tabbarcontroller (a custom one).
theSplitController.TabBarItem.BadgeValue = items.Count().ToString();

How to add TabBarItem to default TabBarController without setting it as ViewController

I'm not using a custom TabBarContoller. Instead of this, i created a TabBarController on storyboard and add my ViewControllers from there. However i need to bind a TabBarItem with UIImagePicker just like clicking button to open UIImagePicker, so there is no need to add another empty ViewController i guess..
I'm not able to drag and drop a new TabBarItem it to TabBarController. Is there a way to do this without implementing a custom TabBarController ?
No, you can't do that -- the tab bar items come from the content controllers, not directly from the tab bar controller. You'll have to add a separate controller, from which you can launch the image picker in its viewDidAppear method, so it will show up as soon as you switch to that tab.

Adding Tab Bar Controller to Root View of UISplitViewController?

How would I set a UITabBarController with all its individual view controllers as the root view in a split view? IB doesn't seem to let me change the class of the root view controller to anything else…I'm using Xcode 4.
Are you using the split-view based application-option? In that case, it worked for me to just extend : UITabBarController in the RootViewController.h-file. I'm not sure what behaviour you want here, but if you set it up like that, you should get the tabbar with all your views (you have to add them in RootViewController.m ofc) in the "root"-option on the navigation bar.
If you want the DetailView to show the same, you have to add a navigationcontroller to the detailview as well.
As for the "more elegant" solution with IB, I'm afraid I'm not very fond of or very experienced with IB.
You want to add tabbarcontroller to your split view at rootview side and its very simple.
create as many viewcontrollers subclasses with xib for ipad as u want to put in tabbarcontroller.
Then expand your splitview , u have two things navigationcontroller(which in turns contain rootview controller),detailview controller(right side view).
Open your library just drag tabbar controller exectly onto navigationcontroller ,so it will replace all that navigation controller and rootviewcontroller(i assume u dont need that rootview controller or u can create it later).
now expand this tabbar controller u can see viewcontroller 1 - viewcontroller 2 etc.
Now simply select view controller 1 , open attributes and select nib file on [command 1 attribute] and select controller file for that nib file by press[command 4 attribute].
Reapet this for view controller 2 in tabbarcontroller and save close IB.
run program select landscape then u can see its done.
Thanks to dh14-sl and lecou—the solution was a combination of both your answers. I was trying to drag a tab bar controller from the library onto the list of elements but it wasn't working—turns out I had to drag it to the view itself. Then I had to change the parent class of my rootvc and re-setup connections, but now it seems to work! Thanks guys!

iPhone - Tweak the UINavigationController to show a UINavigationBar made into IB

I've build a UINavigationBar into Interface Builder, and I have a NavigationController into my app. I'd like to make the one use the other to work. Just to manage the bar into IB and let the controller use it as its view (and adding by itself the Back button if needed), or in another way to do the same thing, let the NavBar use the navcontroller to adjust its display.
Do you see a way to do this ?
If not, I really don't see the use of the NavigationBar proposed into IB.
If you create the view controller in IB, you can give it a navigation item (UINavigationItem), and put your buttons in there. If you only create the view in IB and the controller is the owner (you use initWithNibName:bundle:), then you will either have to create the items programatically or put a outlet named navigationItem in your custom controller and connect it to a navigation item in the nib.