

- #Swift share nib between two view controlelrs how to#
- #Swift share nib between two view controlelrs code#
- #Swift share nib between two view controlelrs series#

or not.įor example, if you have two sbuviews that are each tableViews, you may want to have one view controller for each tableView. However, depending on the complexity of the views (including their content), you may want separate view controllers. Most views contain many subviews, which are views themselves, so this literally doesn't make sense. There isn't necessarily a 1-to-1 relationship between view controllers and views.
#Swift share nib between two view controlelrs code#
The above use case is not exactly my use case but it's one that clearly describes the problem without getting bogged down in my development app.Īlso I know I could have written all the sub views as code but each sub view has a complex layout of child views and it would be a lot of code and messing around to try and get them looking right. Still want to keep everything in Interface Builder?īefore anyone asks why don't I just display the sub views on a new screen and use the navigation bar, let me say that I have very good reasons and I do understand iOS UI guidelines.
#Swift share nib between two view controlelrs series#
This is achieved with a single view controller with an associated nib file and a series of additional nib files for the sub views which are loaded in the view controller's viewDidLoad method. To summarise I have a single screen iPhone app that has layered views that are shown/hidden by clicking buttons. The code above is repeated for the other views. I could have created all the views in code but this would require a lot of tedious coding as the layouts of each sub view are quite complex (with multiple child views).Įxample code loading a sub view from a nib file. The idea behind this was to avoid having multiple views stacked on top of each other in a single nib file as this would be hard to manipulate in IB. I'm then loading the sub view's nib file in the view controller's viewDidLoad method using the UINib class. Too make managing the UI easier in IB I've decided to create multiple nib files for each sub view that is to appear when clicking the relevant button. Clicking another button hides the previous overlay view and displays another one. Clicking on a button displays an associated view which overlays the buttons.

The app has a single screen that displays a series of buttons. This class will own the data and all the data handling functions.ĭoes this general organization work, and is it consistent with best practices? Is there another way that would be better for solving this problem? Any advice that you have would be greatly appreciated.I'm using interface builder to create the UI for an app I'm working on. My current thinking is that I'll create a parent class for all of these view controllers to inherit from. But I don't want to use globals in the AppDelegate. What I'd like to do is have one data source that they are all accessing. The rest of the view controllers just pass the data back and forth, which is getting a bit crazy. Right now, one of these view controllers (a table view) pretty much "owns" and saves the data. So, they all work from this one data set, to varying degrees. Others access and modify a single choice from this array. Two of these access/modify an array of Choices. I have a data model defined for an object, Choice.
#Swift share nib between two view controlelrs how to#
I am new to swift and app development, and have a question about how to best organize data for a simple app.
