Simple iPhone Application Development


Here We are going to create a simple iOS App, for this you need a Mac iOS and Xcode IDE. Just follow these steps and you can create a simple “Hello World” program.

Step 1 

Open XCode and click create new project as shown in below image.



Step 2 

Select an empty application



Step 3 

Enter project name and set device family as iPhone.



Step 4 

Set project location and click create button.



Step 5 

Your project will be created as shown below.



Step 6 

Project property windows contains appdelegate files and other supporting files. We need to create a screen/class with xib(user interface). Right click on the project folder and select new file as shown in the below image.



Step 7 

You have to select Objective-C class and Click next.



Step 8 

Rename the class to homescreen(what ever you wish) and select UIViewController in the Subclass of dropdown and check the “with XIB for user interface” to include user interface file and click next



Step 9 

It will ask you to select location to create file. You no need to change the default location. You can click create button.



Step 10 

Home screen has been successfully created and it will look like below image.


Now open homescreen.h file and create a UIButtonField with its onclick function programmatically with the below mentioned code.

@interface homescreen : UIViewController
{
    IBOutlet UIButton *btn_hello;
}

@property(nonatomic, retain)IBOutlet UIButton *btn_hello;

-(IBAction)btn_hello_click;

@end


Now your homescreen.h file will look like this



Now open homescreen.m file and synthesize your button field at top and add a alert box in the button click function as shown below

@synthesize btn_hello;

-(IBAction)btn_hello_click
{
    UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Success !!!" 
    message:@"Hello iPhone" 
    delegate:self cancelButtonTitle:@"OK" 
    otherButtonTitles:nil];
    [alertView show];
    [alertView release];
}

The memory allocated by the button has to be released manually as shown below

- (void)dealloc 
{
[btn_hello release];
[super dealloc];
}

So your homescreen.m file will look like the below shown image



Step 11 

Now it’s time for design part. Open the homescreen.xib file and drag a button in the right side object window and drop it in the view controller.



Step 12

Now double click on the button and enter text as “Click Me !”. 



Step 13

Now under objects panel on left side, right click on the button as shown below




Step 14

Now click on the “Touch Down” option and link it to “File’s Owner” as show below. 



Step 15

Now the button click function declared in header and main file will get pop up. 



Step 16

Select the function. This process will link the function to the button click event.



So design part is over. Now your application is ready. But, the problem is this is an empty application. Application don’t know where to start. So we need to redirect the application to the home screen.

Open Appdelegate.h file and declare UINavigationController as shown below

@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
   UINavigationController *navigationController;
}

@property(strong,nonatomic)UINavigationController *navigationController;

@property (strong, nonatomic) UIWindow *window;

@end

Your Appdelegate.h file will look like this



Step 16

Now open AppDelegate.m file and mention the homescreen to be the start point of the application as shown below

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{
UIViewController *homeController = [[homescreen alloc] initWithNibName:@"homescreen" bundle:nil]; 
navigationController = [[UINavigationController alloc] initWithRootViewController:homeController]; 
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}


Step 17

Your AppDelegate.m file will look like below image. Now it’s done. Click on the run icon on the top left corner as shown in below image.



Step 18

It will take few min to open the iphone simulator and your project. Your application will look like below image


Step 19

Now click the “Click Me !” button.



Congratulations. You are now a iPhone developer.

Labels: iPhone development, simple ios app, develop simple ios app, ios app, 1st ios app

Comments

Popular posts from this blog

Create Desktop Application with PHP

Insert pandas dataframe into Mongodb

Python desktop application