Objective-C basic interface

In this tutorial, we will see how to create a basic interface in Objective-C with code only. It will be one TextField and one Button. Yeah, just that and we will need 6 files! And maybe we will use some inheritance.

ActionScript 3 is really a smart language, it is very quick to create what we will do. Something like 10 lines of code… Anyway, in this tutorial I will not make comparisons between ActionScript 3 and Objective-C like the previous one unless it is really useful.

Open Xcode and create a new iOS empty application, disable everything. Many files are created, but we will use only AppDelegate.h and AppDelegate.m In the AppDelegate we will init our applications.

Objective-C is based on the MVC design pattern, so we need to implement it :
Create a new UIViewController subclass file and name it MyViewController, don’t select XIB option, and create a folder “controllers”. Your files are created in the folder but you don’t see that in Xcode. Select the files, right click and select “New Group from Selection”. Rename it in “controllers”.
Objective-C doesn’t support package!

Then we have added the view to our view controller thanks to the loadView method. It comes from UIViewController! Afterwards we have initialized our MyView class, giving some params, and finally added it and its button :

In this tutorial we saw the 3 primary objects (NSObject, UIView and UIViewController) and how to assemble them. If you are creating an app for the iPhone & iPad, you will use Xcode’s Interface Builder with xib file. It is really smart, you just have to drag & drop interfaces and “draw line” to make connection between them and code.

On the internet, some people use NSRect NSColor objects for their view and design. I couldn’t use most of the NS object in my example… maybe there is a difference between an app on Mac and iOS. If someone could explain it, that would be great!
Finally it’s not learning a new language which is hard, it’s learning its API 😉

I don’t think that I will made basic tutorials on creating iPhone apps, there are already lots of resources on the internet. I will focus on game engine, Cocos2D and Sparrow!