How see code-view for view controller in Xcode? - ios

In my Xcode project, I have several view controllers in my storyboard. How can I see the code for a specific view controller?
Because each view controller will need to have different functions from the others. So, where can I write that code?
Thanks!

By default, storyboard will use UIViewController for the view controllers you use.
However you can change the class used for the view controller by:
selecting the view controller (in Interface Builder)
show the identity inspector (View > Utilities > Show identity inspector)
Change the value in Class to "MyOwnViewController"
Where "MyOwnViewController" is the name of the UIViewController subclass that you want to use for that view controller.

The "Show the Assistant editor" venn diagram icon on the top right did it for me.
Xcode Version 6.4

Select the View Controller you want to see the code
Go to the Assistant editor
It's on the upper bar to the right.

Select the storyboard in the navigator, right click and select 'Open As'. You should see 2 options 'Interface Builder - Storyboard' or 'Source Code' - select the Source Code option should fix your issue.

You subclass each UIViewController to add unique functionality. The implementation of UIViewController is private to Apple, the interface is described in it's documentation.

We start with multiple scenes in our storyboard.
see picture
Create new view controller file
Create new swift file
For our custom view controller
see picture
Setup file
In our new file,
Type in code
To set up class structure
see picture
link file to view controller in Storyboard
In Storyboard,
Click on our view controller
pic a
pic b
pic c
In the Identity Inspector,
In the Class field,
Type in the name of the new view controller file we created in step 1
open Assistant view
see pic
Done!
We are ready to write code
In our view controller
That is connected to our view controller in the Storyboard
see pic

Related

Storyboard assistant editor for a ViewController opens <projectName>-Swift.h instead of <viewController>.swift

I have a programmatic swift project that I'm converting to Storyboards. A particular interaction is grinding my gears.
When I click on a view controller MyViewController in a storyboard, the assistant editor opens up myProjectName-swift.h instead MyViewController.swift
I know I can click on the nav bar of the assistant editor and select my VC from the automatic drop down list but this is just adding more actions every time I switch VCs in storyboard.
When you set you class to match your view controller, usually the assistant editor will open the right file.
This is how to select the class:
Select your view controller in storyboard
Open the identity inspector
Select the class from the list
That -Swift.h file was generated by swift 2.2 and lives in the derived data folder.
After clearing derived data the problem seems to have resolved itself

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.

How to use a new view controller in new xcode 6 single view project?

I created a new Single View project in Xcode 6. I run the app, it looks fine.
I go to Main.storyboard and delete the view controller there. I then drag a new "View Controller" into the Main.storyboard. What do I need to do to successfully run the app without any runtime exception? I have done the following:
1- Check the "Is Initial View Controller"
2- Give the new view controller a Storyboard ID
Click on the ViewController, then Identity Inspector (the tab where you've set the Storyboard ID) and check if the custom class is set correctly. It should be the name of your main .h file, the one you want to set as first View.

Can't use the drag function in .h when using storyboard with more than one view controller

I can't use the control drag function to hook up a button to action in .h when using storyboard with more than one view controller
Please help me...
Are you sure you've assigned the view controller a custom class? and dragging to that specific class? Each view controller should have its own Obj-c class. To create one:
press cmd + n and create a new Objective-C class and make it a subclass of UITableViewController (or the view controller you used in your Storyboard). after doing so, go to you Storyboard and select the view controller, on the right menu choose "Identity Inspector" and set the custom class name to the name of the class you just created.
Set the class file name for the UIViewController of the storyboard file at the identity inspector .

Cant add new xib's to view controller

I am working on one view controller which has three static screens which i m going to show to user for first time when he installs the app, for next time forever i will show him main functional view.
Problem is
When i have created viewController class i never selected xib option.
Now i have added two xib's (iPhone and iPad) in project.First i deleted the present view from it then I have created three static views in each which contains some label and one button in each..
I want to add those views in my view controller's view. and i want to add targets for buttons in those view.
I am unable to reference outlets in my class for all three views
and can't add target for buttons in my viewController.
How can i do that??
Please help......
Solved it..:)
Problem was when i have added new xib file to project.i deleted the present view controller view from xib...thats why xib was unable to find any of the projects view controllers in custom class drop down
When you click on the File's owner on the left while the XIB is opened:
Select the the third icon on the far right, and make sure the correct class is selected under Custom class, the green textfield:
You need to select File Owner then go to the identity inspector in right pan of Xcode where you can select yor Xib name :)

Resources