Hey, so, I see that you want to make an iPhone app too? Well, today’s your lucky day! I’ll try to make this really easy! First, here’s what you’ll need:

  • The iPhone SDK that can be downloaded from Apple’s website
  • Note for PPC users: Look at this
  • A development device [don’t need one, but recommended, and it needs to be registered as an iPhone Developer]
  • Some wits!

Let’s get started! I assumed you installed the SDK by now, if not, do it. Make a new project {Apple + Shift +N}, let’s name it “View-Based App”.

 

 

     As a side note, you need to know what files do what. To start, all of the “.framework” files are the main framework and will “tell” Xcode what API’s are where. The Info.plist is the App’s “Hello my name is” card. As with all C-based executables, your app will have its “main.m” file, but like the “View_Based_App_Prefix.pch” it wont need editing unless you want to use other frameworks. The “MainWindow.xib” [it’s a nib by-the-way, but why xib?] and the “View_Based_AppViewController.xib” are the files generated by IB [Interface Builder] and contain the App’s interface, but for this app, we’ll stick to the “View_Based_AppViewController.xib”. The “View_Based_AppAppDelegate”, is, as you can see, the app’s delegate—everything goes by that file—last, but not least, the “View_Based_AppViewController” is the controller that controls your view [the XIB].

     As you may have noticed, there are two main types of files: .m and .h. The .m are specific to Objective-C, which is a really powerful tool if you know how to use it correctly. The .h files are headers, where you declare objects (a button, label, toolbar, etc.) and functions.

 

 

 

Now that you understand what files are in your project, let’s start! Choose the “View_Based_AppViewController.h” file. We’ll want to add six buttons, and two labels like this:

 

 

     Add the following text between the two brackets of the View_Based_AppViewController function:

//labels
IBOutlet UILabel *myInstructions;
IBOutlet UILabel *myAnswer;
//buttons
IBOutlet UIButton *myFirstButton;
IBOutlet UIButton *mySecondButton;
IBOutlet UIButton *myThirdButton;
IBOutlet UIButton *myEnableButton;
IBOutlet UIButton *myDisableButton;
IBOutlet UIButton *myClearButton;

     Please note that the colors are really important and makes your life a whole lot easier.

     The pink is for what type of declaration this is. In this case, it’s going to use Interface Builder. The purple color is for the type of UI [User Interface] item and the green is for the item’s name.

     This is the [easy] [and fun] tricky part, once you’ve got all of your items setup. Please watch the following YouTube video I prepared for you guys, it will be easier to watch and redo then to read and redo. Don’t close IB yet, we’re not done with it, we need to open up Xcode [if you closed it].

Go back to that header and add the following lines:

When the function closes (at the }), add these lines:

– (IBAction)myFirstButtonClicked:(id)sender;
– (IBAction)mySecondButtonClicked:(id)sender;
– (IBAction)myThirdButtonClicked:(id)sender;

– (IBAction)myEnableButtonClicked:(id)sender;
– (IBAction)myDisableButtonClicked:(id)sender;

(IBAction)myClearButtonClicked:(id)sender;

Go back to IB and do what I do in this video.

Once that’s done, open up “View_Based_AppViewController.m”, add the following functions:

– (IBAction)myFirstButtonClicked:(id)sender
{
if (myInstructions.text==@”What does 1+1 equal to?”)
{
myAnswer.text=@”Wrong”;
myAnswer.textColor=[UIColor redColor];
}
}
– (IBAction)mySecondButtonClicked:(id)sender
{
if (myInstructions.text==@”What does 1+1 equal to?”)
{
myAnswer.text=@”Right”;
myAnswer.textColor=[UIColor greenColor];
}
}
– (IBAction)myThirdButtonClicked:(id)sender
{
if (myInstructions.text==@”What does 1+1 equal to?”)
{
myAnswer.text=@”Wrong”;
myAnswer.textColor=[UIColor redColor];
}
}
//
– (IBAction)myEnableButtonClicked:(id)sender
{
myFirstButton.enabled=YES;
mySecondButton.enabled=YES;
myThirdButton.enabled=YES;
}
– (IBAction)myDisableButtonClicked:(id)sender
{
myFirstButton.enabled=NO;
mySecondButton.enabled=NO;
myThirdButton.enabled=NO;
}
//
– (IBAction)myClearButtonClicked:(id)sender
{
myAnswer.text=@””;
}

In the “viewDidLoad” function, add this before the [super viewDidLoad];:
myInstructions.text=@”What does 1+1 equal to?”;
myAnswer.text=@””;

     And now we’re done! If you got lost during the How-To, don’t worry! Here’s a zipped copy of the finished product, comment this if you want tips and I’ll email you back!