Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.h and .m files for view controllers added within storyboard xcode 4

Tags:

I've created the flow of my application with storyboard. It's a navigation based storyboard layout with a few stacks of views. Where can I create .h and .m files to actually make the app DO things? The general navigational flow of the app is just fine as a result of story board, but I need to add my own code to the views. Thanks!

like image 526
Matt Rosemeier Avatar asked Jan 03 '12 03:01

Matt Rosemeier


People also ask

How do I create a .m and .h file in Xcode?

To create a Objective-C class, you have to select "Cocoa class". This will create an . h and . m file for you.

How do I add a view controller in Storyboard?

To create a new view controller, select File->New->File and select a Cocoa Touch Class. Choose whether to create it with Swift or Objective-C and inherit from UIViewController . Don't create it with a xib (a separate Interface Builder file), as you will most likely add it to an existing storyboard.


1 Answers

Go to File->New->New File and create a UIViewSubclass without the xib/nib for each view that you have. This will create the .h and .m files. Then, select the view in the storyboard and go to Identity Inspector in the right column view. Under Custom Class->Class, select the new UIViewSubclass (by name) that you just created. This will link the view with the header and implementation files.

like image 93
Greg Avatar answered Oct 17 '22 14:10

Greg