Simple application in iPhone

This is the Simple application . In this this application you select the answer from the given data for the question. If you given the right answer it will show “Correct Answer” otherwise it’ll show “Wrong Answer”. So let see how it will be worked.

This is the Simple application . In this this application you select the answer from  the given data for the question. If you given the right answer it will show “Correct Answer” otherwise it’ll show “Wrong Answer”. So let see how it will be worked.

Step 1: Create a application using View base template. Give the application name “ViewbaseApplication”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Xpand classes and notice Interface Builder created the ViewbaseApplicationViewController class for you. Expand Resources and notice the template generated a separate nib, ViewbaseApplicationViewController.xib, for the “ViewbaseApplication”.

Step 4: Open the ViewbaseApplicationViewController.h file , we have added UILabel for display , UIButton for button and add methods. So make the following changes:

#import <UIKit/UIKit.h>

@interface ViewbaseApplicationViewController : UIViewController {
       
        IBOutlet UILabel *question;
        IBOutlet UILabel *selectlabel;
        IBOutlet UILabel *answer1;
        IBOutlet UILabel *answer2;
        IBOutlet UILabel *answer3;
       
       
        IBOutlet UIButton *firstAnswerbutton;
        IBOutlet UIButton *secondAnswerbutton;
        IBOutlet UIButton *thirdAnswerbutton;
        IBOutlet UIButton *cleanAnswer;
}

-(IBAction)firstAnswerbutton:(id)sender;
-(IBAction)secondAnswerbutton:(id)sender;
-(IBAction)thirdAnswerbutton:(id)sender;
-(IBAction)cleanAnswer:(id)sender;

Step 5: Double click the ViewbaseApplicationViewController.xib file and open it to the Interface Builder. Drag labels from the library and place it to the view window and drag Round Rect from the library and place it to the view window.Connect File’s Owner icon to the view icon select the view. Select File’s Owner icon to the each of label and button . Select CleanAnswer button and bring up connection inspector and drag TouchUpInside to the File’s Owner icon and select cleanAnswer: action, select firstanswer button and bring up connection inspector and drag TouchUpInside to the File’s Owner icon and select firstAnswerbutton: action. do it for next two answer button and select the secondAnswerbutton and thirdAnswerbutton  action (See the figure below). Now save the ViewbaseApplicationViewController.xib file, close it and go back to the Xcode.

Step 6: In the ViewbaseApplicationViewController.m file, make the following changes:

- (void)viewDidLoad
{
        question.text=@"What is 9*9 equal to?";
        answer1.text=@"";
        answer2.text=@"";
        answer3.text=@"";
    [super viewDidLoad];
}

-(IBAction)firstAnswerbutton:(id)sender
{
        if(question.text == @"What is 9*9 equal to?")
        {
                answer1.text =@"Wrong Answer!!!";
                answer1.textColor=[UIColor redColor];
        }
}

-(IBAction)secondAnswerbutton:(id)sender
{
        if(question.text == @"What is 9*9 equal to?")
        {
                answer2.text = @"Wrong Answer!!!";
                answer2.textColor=[UIColor redColor];
        }
}

-(IBAction)thirdAnswerbutton:(id)sender
{
        if(question.text == @"What is 9*9 equal to?")
        {
                answer3.text =@"Correct Answer!!!";
                answer3.textColor=[UIColor redColor];
        }
}

-(IBAction)cleanAnswer:(id)sender
{
        answer1.text=@"";
        answer2.text=@"";
        answer3.text=@"";
}

Step 7: Now compile and run the application in the Simulator.

You can download SoureceCode from here ViewbaseApplication

WP Greet Box icon
Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic, and free programming tips and tricks and source code            snippets.

4 Responses to “Simple application in iPhone”

  1. Patrick says:

    Thanks for these tutorials.

    “What does 9*9 equal to?” should be:
    “What is 9*9 equal to”.

    • anonymous says:

      brush up your grammar Patrick.. both sentences are correct. the first one employs “equal” as a verb..BTW it is not about the grammar..did you like the article?

  2. Patrick says:

    Sorry, left the question mark out of my earlier post:

    “What does 9*9 equal to?” should be:
    “What is 9*9 equal to?”

  3. Sushant says:

    Did you checked it on your simulator? I have checked but it working fine on the simulator. If there is any problem please let us know.

Leave a Reply

Security Code:

learn iphone programming

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Our Mobile Training Courses

EDUmobile.ORG offers the following 4 Mobile Training Courses. Our iPhone Training Course is very popular, with over 200 developers in training.

learn iphone programming
© 2010 EDUmobile.ORG