5

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: enter image description here
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.

Niv
  • 2,294
  • 5
  • 29
  • 41
  • Not enough information here for someone to help but nothing in the image suggests an error. I suggest adding some `NSLog`s to each View Controller (probably `viewDidLoad`) to make sure that the correct information is being passed and that the correct UIViewController class is being instantiated. Note that each should be unique. It's the only way to debug something this complex. – Robotic Cat Oct 26 '13 at 17:38
  • Both the viewDidLoad and loadView are called just once - The PostListVC is probably not getting instantiated correctly, but I don't know why. – Niv Oct 26 '13 at 18:16
  • A few things to check: Is the class set correctly inside IB? What do `NSLog`s in PostListVC tell you about it? Is the view connected in IB? Not sure I can help beyond these questions. – Robotic Cat Oct 26 '13 at 18:26
  • I have added an example project that illustrates this problem – Niv Oct 26 '13 at 19:11
  • This seems like a bug to me. I suggest you log it with Apple at http://bugreporter.apple.com with your initial problem (example project 1) explaining that if you use the solution (example project 2) you cannot have different item names. – Robotic Cat Oct 26 '13 at 19:50
  • I've just built this from scratch and as soon as the `UINavigationController`s point to the same `UIViewController` they stop working. They can point to different `UIViewControllers` which are the same class and have the same UI but they must be different objects in the Storyboard. So I would log as a bug and see if Apple can fix in a later release. For now you will need to work around it in the Storyboard. – Robotic Cat Oct 26 '13 at 19:59

2 Answers2

0

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.

jamihash
  • 1,900
  • 1
  • 12
  • 15
  • 4
    Is there a way to make all 3 share the same xib? I currently hold all the design inside the storyboard – Niv Oct 26 '13 at 18:17
0

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:

enter image description here

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.

Robotic Cat
  • 5,899
  • 4
  • 41
  • 58
  • 2
    I have gotten to this solution as well, however: 1)Using this way you can't create different tabBarItems for the different views (for example if u have different images for the buttons). 2)It bunches up the barItems - you can't add a different tabBarItem between the 2 that link to the same viewController. (Example to this issue added in EDIT 2) – Niv Oct 26 '13 at 19:45