Question

I have one UIViewController with two UIViews on it. In the Navigation bar, when one button is pushed one of the UIViews is displayed and when the other button is pushed the other UIView is displayed. I want to put a UITableView on one of the views. However, the UITableView requires the UIViewController to use the UITableViewDelegate and UITableViewDataSource. Having implemented this for my UIView (subview) containing the UTTableView, when I click on the button for the other view, which does not contain a table, I get errors and the application croaks.

I am assuming (possibly incorrectly) that my issue is that I am trying to use the same UIViewController for both subviews, but only one contains a table.

Question 1) Is it possible to do what I described above? Meaning, if I had a problem then something was not connected up correctly.

So, I went down a path of creating two separate UIViewControllers; one for each view. Not sure this is the smart approach. Now I am just looking for advice on the best way to do this. Thank you in advance for your help.

enter image description here

To be more clear about what I am trying to do. I want the blue view to be put where the pink view is when the first button on the bar is clicked and I want the yellow view to be put where the pink view is when the second button is clicked. Essentially the pink view will never be displayed and may not even need to be on the UtilityViewController.

Was it helpful?

Solution

Having each as a UIViewController (or a subclass thereof) is the way to go about what you are trying to do. The UITabBarController does this already: https://developer.apple.com/library/ios/documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top