Set up UITabBarController with three other view controllers - ios

I have a UITabBarController inside of a TabBarViewController. I want to use this to connect my three other view controllers to a tab bar.
What I have so far: I have my three view controller, each with one UIView inside of them, ready to be paired with the tab bar to give easy navigation between them. I have also made a new Objective-C class of type UITabBarController. Inside the .xib of that I deleted the UIView and replaced it with a UITabBarController (not sure if this is right).
I'm new to Objective-C and Xcode so I don't know a whole deal about it all, so I may be doing this all wrong. Please correct me and try not to be too vague, thank you!

There's a tutorial here with two tabs:
http://www.youtube.com/watch?v=NfEK9JsCyXM
You can watch it and work with it to make it do 3 tabs.

Related

Can't link my UITableViewController to my nested UITableView

I need to provide some background to explain how I got to where I am. I'm trying to create an interaction that involves different segues (slide up from the bottom, slide in from right) and, as far as I can tell I can't mix these two styles amongst scenes that are embedded in a Navigation Controller because the Show segue will only appear from right to left if I do.
The behavior I want is: Initial View Controller -> Settings (segue from bottom) -> -> detail for selected Setting ('standard' segue from right to left)
I also want to put a navigation bar in the Settings view so I can have a Done button that will close the view (slide out of sight from top to bottom) like this:
Interface builder won't let me add a navigation bar when I'm using a Navigation Controller and without one it looks like this:
So, I tried something from a thread that suggested nesting views. It almost works (the first screenshot above was taken from that code), but it resulted in a new problem. That problem is that I can't link the nested `UITableViewController' to my SettingsTableViewController.swift custom class. It's simply not an option in the dropdown list of classes and so I can't configure my table of Settings options.
Here's the hierarchy I now have based on the suggestion from that thread:
Also, I've confirmed that my SettingsTableViewController.swift is subclassing UITableViewController.
I'm stumped and would really appreciate some help.
If you try this,
Add a UIViewController and a UINavigationController(this automatically comes with a UITableViewController.
For example sake, add a button to the UIViewController, right click and drag to the UINavigationController and setup the segue to the following show in the image.
Add another UIViewController and right click drag from the UITableViewController to the new UIViewController and use a push segue, which you can reference when you do 'didSelectRowAtIndexPath'.
You shouldn't need to connect things, because your UITableViewController is the rootViewController of a UINavigationController. If you use a UITableViewController the only thing you should have in it's hierarchy is the UITableView, if you want other things, you need to use a UIViewController and add a UITableView, but I don't think you need this because you can achieve your requirements with the default options.
Comment if this does not make sense, good luck,

Using multiple copies of the same view controller in a storyboard

I have the following setup in my app:
My initial view controller is a UITabBarController.
the tabs:
1)UINavigationController->PostListVC
2)UINavigationController->CategoriesListVC
3)UINavigationController->PostListVC
4)UINavigationController->PostListVC
5)UINavigationController->MoreViewController
As you can see, 3 tabs contain the same viewController class, but should not contain the same view controller object - the view will display different information based on information he gets form the AppDelegate.
What I did is I created 5 UINavigationControllers, connected them to the uitabbarcontroller, then created a rootViewController segue for 3 of them to the same PostListVC View - that way I don't need to maintain 3 designs of the same view.
The problem that I get is that only the first PostListVC gets created properly ( the leftmost in the tab bar ) - the other tabs that point to a PostListVC just show a black screen.
I've tried to illustrate the way I wire-up the storyboard using a 3-tab example:
As you can see, both the upper-most and lower-most views are connected to PostListVC.
I do not know what the issue is. I assume I'm using storyboards somewhat wrongly.
Does anybody know how I can fix this?
Thanks!
EDIT:
I have created a simple, example project (Xcode 5) that illustartes this issue:
http://www.speedyshare.com/Srwfg/TabBarProblem.zip
EDIT 2:
A modified version of the example, showing the problem with the offered solution:
http://speedy.sh/JkdGC/TabBarProblem-2.zip
There is no way to create different tabBarItems with this method, and there's no way to place the barItems so that they're not in a row - even if you try to chagne the order of segues.
As you said you need three different instances of PostListVC then you should create three different viewcontrollers of type PostListVC and connect each tab to its own. The class is the same but each tab gets its own instance.
I have got your example program to work BUT I don't know if the solution will work for your full project. Hopefully, it will put you on the correct track.
The solution is to have ONE (1) Navigation Controller / embedded root view but TWO (2) segues from the Tab Bar Controller. Here's the picture:
It looks like there's a problem with multiple UINavigationControllers linking to the same UIViewController. But no problem with the same UINavigationController linking to the same UIViewController provided they are instantiated separately through the UITabBarController.

Tabbed application (template), need one controller to have a static table view

I just created a new xcode project with the 'Tabbed Application' template. I have a tabbed application with two tabs therefore two controllers. Both controllers are of type UIViewController. I made one of my controllers the 'settings' controller. I added a nav bar with a title of 'Settings'. All is well so far.
Then I add a TableView to the settings controller and make it a static table. Apparently I cannot have a static table view inside of a normal ViewController, it needs to live in a TableViewController.
Here is where I get very lost (still very new to iOS programming).
Am I supposed to delete the ViewController that the template provided and add a new TableViewController? I tried this however I cannot add a navbar to this type of controller.
Or is there some way to shove a TableViewController into the ViewController to get things to work.
I have looked all over today and most examples of TableViewControllers I have found are not in a tabbed application so they just create a TableViewController and move on.
Oh I also need to be compatible with iOS 5. Not sure if that makes a difference with TableViewController stuff.
Any help would be greatly appreciated.
Thanks.
Update: other option: you can follow this tutorial too.
Yes, of course you can:
Delete de UIViewController
Add to your storyborad a new TableViewController
Select it and go to Editor Menu->Embed In->Navigation Controller
Connect it to your tabbar in the storyboard
Update: other option: you can follow this tutorial too: Tutorial: Storyboard in XCode 4.2 with Navigation Controller and Tabbar Controller (Part 1)
Hope it helps!

iOS App ECSlidingViewController: add new viewcontroller and transient to it

I use ECSlidingViewController in my App. There're four ViewControllers come with the sample code. These four ViewControllers corresponds to four option in the "MenuViewContoller".
Now I want to add a TableViewController in the "FirstTopViewController". Each cell of this TableViewController leads to a ViewController which is not one of the four predefined ViewControllers.
I saw that ECSlidingViewController ships a 'SampleTableViewController". But I don't know how to 'transient' to this ViewController.
I did work with UINavigationController before. I know how to push a view controller to NavigationController. I don't know how to cooperate UINavigationController with ECSlidingViewController.
Thanks a lot.
Here is a demonstration:
http://www.penghou.net/file/question.png
ECSlidingViewController is a container, just like UINavigationController. You give it view controllers and it displays and transitions between them.
ECSlidingViewController provides methods for setting view controllers and transitioning between them by calling anchor/reset. Check the header file for documentation on these methods.

Two UITabBarControllers sharing one ViewController (as tab content)?

Situation: two UITabBarController's, each with their own tabs, but last tab in both is identical so want one UIViewController to show content.
Issue at runtime: Shared item only appears in one of the tab sets when shown.
Question: anyone know a way to make this work?
Link to external graphic of storyboard setup: (sorry, don't have enough reputation to post images here!)
Storyboard graphic
An Xcode project with that storyboard:
XCode Project
Each tab content item has it's own UIViewController class. They contain no code except the line to make the back buttons work.
(Yes, I know this is odd. Real situation is an iPad app where tab controllers are shown in popovers; popovers are "property editors" where different objects have different properties, but all share a common set of properties... thus one tab for "unique" props, one shared tab content for the "common" props all objects have.)
I've found a couple ways around this to get the effect I want, but if this storyboard worked it would be a much easier solution.
-- Other info, somewhat unrelated to question --
Alternate solution I'm using: TabBarControllers only link to one VC as tab content. When that tab VC loads, I use code to (a) instantiate shared VC from storyboard by identifier, (b) add that new VC object to the TabBarController via [tabController setViewControllers:list animated:NO].
(Another possible solution I like even less: not using a TabBarController, and presenting content VC's with my own "tab" graphic drawn into them, each showing "myself" as selected. Yuk.)
So I have a working solution, I'm just curious as to why this doesn't work (just a known thing in iOS API, or some magical property setting that might render it functional?)
You can't put the same view controller instance into two tab controllers. The problem is that a view (UIView) instance can only have one parent view (superview). When you try to add the view controller to the 2nd tab, the view controller's view gets removed from its first parent (the first tab) and then added to the 2nd tab.
I stumbled upon your thread while running into the same issue today...
The solution is to just make a duplicate of the view controller in story board and attach the duplicate to the other tab bar controller.
I just did it and it works...
I think the 'rdelmar' is right about this... copy it and set it ..!!
I ran across this same issue today. I managed to come up with a workaround that seems to do the trick. The key is to add a layer of separation between the tabbar and the controller you want to reuse. From each tabbar, I created a relationship to a distinct UIViewController with a container view. Then you can do an 'embed' segue from the container to the controller you actually want to reuse as the tab view. It is not quite as clean as a direct connection (not sure why that is not supported) since you do have to create a controller class for each reuse case. It is still a better solution than the nightmare of having to duplicate the actual tab view ( as well as any additional views that connect to it) for every use.
Hope this helps. Let me know if anyone needs more details.

Resources