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

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.

Related

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

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

Base UIViewController for entire app with views inside

I want to create base view controller for my app, all other view controllers will subclass it. It will contain some controls inside.
How I can achieve that? For creating design, should I drag new View controller on storyboard and don't connect it anywhere (then You have warning all the time). i Would like to create outlets and make some base implementation. If I use xib file it don't have all guidelines, like one below status bar.

Connect multiple view controllers from storyboard to code in Xcode 6

I created multiple view controllers on storyboard. Now I wanna create several view controller .m and .h files to represent these view controllers respectively. How do I connect the file to its correspondent view controllers? For instance, there are 2 view controllers created and I wanna connect FirstViewController.m file to the first view controllers and connect SecondViewController.m file to the second one.
Select the controller, go to the identity inspector, and change the class from UIViewController to your custom class, which should show up in the pull down menu..
ViewControllers on storyboard can have the same class and you can have different models for each.
now it depends on your needs :
Panel Utility (on left)
identity inspector (3rd from left to right)
chose your class or let the default one if you don't need

Unable to make outlets

I'm not able to create an outlet on the view controller.
I started out with the single view application template, and added another view controller to my storyboard. Now, when I try to create an outlet from the second view controller to the file, Xcode doesn't allow me to make it.
What could be the problem?
When you add a View Controller on a story board you have to change it's class to the View Controller you want it to be controlled by, you can do it by opening the Identity Inspector tab in the Utilities panel (option+command+3) and type or find the class name of the View Controller you want, after doing this, you can play with it's outlets, check out the screenshot:
EDIT: Forgot to mention, you have to have selected the View Controller you want to change the class for in the left list.

Connecting the view controller to the code in swift

When I create two view controllers in the main story board, how do I connect the second one to code?
An example would be:
I put a label in the first view controller called myLabel
I put another label in the second view controller called myLabelTwo
Now, the first view controller can connect to the code easily, but the second view controller 's myLabelTwo cannot be connected.
Create new UIViewController class, ViewController2 for example
In your storyboard, select your second view controller and on the right side menu click on "Show the identity inspector"
Change the Class content to "ViewController2" or whatever else.
You can now connect "myLabelTwo" to your "viewController2"
Please check this link to understand storyboard and view controllers.

Resources