Swift : How do i make a master page structure in view controllers? - ios

I am working in a project that it contains a header view. There is a UIImageView inside header view. I want to derive this header view and its appearance (constraints,bg color etc.) on all of my other view controllers. So is that possible to do it just using Xcode designer ?
I created a view controller in storyboard and BaseViewController class.
In second view controller, i created another class and derived it from BaseViewController. But this didn't work.

Create the view in xib the use that view in all viewControllers in all storyboards. For creating a custom view you can see this video:
https://www.youtube.com/watch?v=IrgH522lbfA

Related

Where to write code of embed viewcontroller in containerView

I am working on a project which contains 3 container view with 3 child viewcontrollers. I am new at container view So I want to know where to write code of that child view controllers. I load that viewcontrollers with adding child viewcontrollers in containerview with use of seague.
As per I googled, There are demos like they only load viewcontrollers in containerview with just changing background color.
I want to know that If I have to make different classes for that view controllers that embed in containerviews?
Thank you for your help
Yes you have to create UIViewController class for each embedded View Controller.
Doing this will give you control over the embedded View Controllers like normal View Controller do.

(Xcode 7.3.1) Not able to connect subview controllers to view controller.swift

I am trying to make a card game with multiple view controllers. I have created my application in a single view application, and have been trying to use multiple view controllers. When attempting to drag the images/buttons into the view controller code, it will not accept it unless it comes from the main view controller. I have posted screenshots that show my problem
You have to make separate class for for every view controller and you have to assign that class to respective view controller from identity inspector from utilities.
Check the screenshot,
So here setting view controller is class , subclass of viewcontroller. So, create subclass of viewcontroller, then select respective viewcontroller from interface builder and assign that class to that view controller and then open that class in assistant editor and you will be able to connect outlets or ibactions.

How to set the controller for a subview in storyboard?

I have a view in my storyboard to which I've added a UICollectionView. Is it possible (using Interface Builder only) to assign to my collection view a different controller than the controller that I use for the view that contains it?
I am using XCode 6.1.
You can add the object to yours main view controller, like in image:
then, set in class in it settings:
and set it like delegate and data source for yours collection view.
I was able to do it by removing the UICollectionView, and replacing it with a Container view. Then, I created a separate collection view controller, and linked it to the container view with an embed segue (ctrl-drag from the container view into the collection view controller, and choose embed).

Embedding TableView in TableViewController into another view

I would like to customize content of table view controller(add some buttons, etc.) but root view for that is table view. Is it a way to embed it into another view and add controls on it?
You can use Container View.
In the storyboard create another view controller that you would use to host those controls. Then drag in Container View from the Object Library (normally the last item in the list) and place it where you want the table view to appear (which could be the whole screen). Doing this, the Container View will create another view controller. Simply delete that and ctrl drag from the Container View to your table view controller and select embed segue.
By doing this, you would not have to change anything in your current table view controller if it doesn't depend on other view controllers to give it data in order for it to work. If it does, however, you could assign the segue identifier to the embed segue, implement prepareForSegue:sender: and do whatever you would normally do with other segues.
You simply add TableView as a subview of a uiviewcontroller. Remember to call for delegates. Normally i don't use storyboards, but if you do it programmatically you can do like this:
On .h file:
#interface EmbeddedTableView : UIViewController <UITableViewDelegate, UITableViewDataSource>
And on .m file simply create your tableView by adding it as subview of viewcontroller.
You can look at this for example: How to set up UITableView within a UIViewController created on a .xib file

How to initialize UITableViewController inside a UISplitViewController?

I just dragged out a UISplitView from the storyboard and set the classes of the root and detail view controllers. I am wondering how to initialize my UITableViewController (as it needs some setup before it is read to be used). This might be easier if I create the UISplitView programmatically. Still, is there a way for me to set up my UITableViewController in the UISplitView? Thanks!
You can just drag and drop a UISplitView to your storyboard and create master view and detail view classes in your bundle. Then assign each class to each viewcontrollers in xib :

Resources