Adding a View Controller in Xcode? - ios

I have created the initial view for my application. This initial view contains segues to new screens/view controllers that I threw together in the Xcode storyboard.
I set audio controls, and background paramaters to my applications initial view using the standard Viewcontroller.h and Viewcontroller.m files that load out when Xcode starts.
My question: how do I programmatically access new viewcontrollers? I.e. 'make a new target' or 'click and drag in interface builder' or something...

Lets say your viewcontroller is called newViewController,
1.drag and drop a view controller
click on the VC.
3.add the name of it in your interface builder under "custom class" and your .h and .m files will both be connected.

Related

how to work with multiple viewcontroll and use the viewcontroll.h and m file

I am new with xcode.
I used one viewcontroller and coded it in the viewcontriller.h and .m files.
My problem is when I add more viewcontrollers, I can't create more action from the new viewcontrollers to the basic files (viewcontroller.h and .m).
For example to right click and drag swipe recognizer from new viewcontrollers to the viewcontroller files (h&m files) in interface builder.
As my comment seems to be the answer, I'll add it as an answer:
I suspect you do want to set the class of the newly added view controllers in interface builder to the class of the view controller you want it to be.
Then, you can drag-connect like with the first one, xcode did set up for you initially.
Also, do remember to use different view controllers for different purposes (you might have to create another subclass of UIViewController).

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.

storyboard linking buttons to .h

Hi i'm just a bit confused on the linking things from the storyboard to the ViewController.h. I've created a new single view application project and when I went to the storyboard I made a button. Now I went to the editor view and ctrl-draged the button onto my ViewController.h which worked. But when i created another view controller on the storyboard with a button on it, ctrl-drag does not work anymore. I've tried typing in myself, -(IBAction)test:(id)sender;, but it wouldn't let me connect to the button on my second view controller.
You did not set your class name in the VC settings.

Xcode: Control drag only works in first storyboard view controller

When I make a project in Xcode and choose template to Single view application, I can only just control drag the first storyboard's view controller elements to ViewController .m and .h. I understand, I chose SINGLE view application, but I think there should be another option.
I tested "Tabbed Application" and that template creates own .h and .m files for every view controller. I tested to rename ViewController.h and .m to FirstViewContoller.h and .m. It was messed now. So, I deleted the project and here I am.
What should I do?
Assuming that you want to create IBOutlets and IBActions in new view controllers.
When you create a new view controller in storyboard, go to Identity Inspector and set Custom Class to the new View controller. Then you can Control drag the elements to the view controller.
When you renamed the files did you rename the #interface and #implementation to match your new class name as well? In the header (.h file) it should say
#interface FirstViewController : UIViewController
and in the implementation (.m file) it should say
#implementation FirstViewController
Hope that helps

can I create a .xib from an implementation file?

I have a project that has the header and the implementaiton files and loads a plain old UITableViewController from the .m but I have no way of configuring the View (I would like to do stuff like ad buttons and text fields onto the view instead of just having a table), should I create a .xib file so that I can modify the view? (Reason I don't just start a new project is that the current project has a bunch of other stuff like OAUTH processes that kick off at the AppDelegate stage to log a user into a system - and I need this functionality). So my question how can I create a .xib from the existing .m .h files and then add other objects which I can then code for.
An answer from this similar question:
"Here's a more step-by-step way to associate your new UIViewController and .xib.
Select File's Owner under Placeholders on the left pane of IB. In the Property Inspector(right pane of IB), select the third tab and edit "Class" under "Custom Class" to be the name of your new UIViewController subclass.
Then ctrl-click or right-click on File's Owner in the left pane and draw a line to your top level View in the Objects portion of the left pane. Select the 'view' outlet and you're done.
You should now be able to set up other outlets and actions. You're ready to instantiate your view controller in code and use initWithNibName and your nib name to load it."
If it's a UITableViewController, simply create a new XIB file via Xcode (File -> New -> iOS -> UserInterface -> View) and then add set the file's owner to your subclassed UITableViewController.
You'll likely want to re-do how the user interface looks -- in terms of dropping objects like the table view and buttons or whatever else -- into the XIB's view. It'll certainly save a lot of time versus trying to debug programmatically creating and adding subviews and actions.
And once that's in place, you can then make IBOutlets and IBActions to your heart's content.

Resources