Hello World with Navigation Base application in iPhone

This is the very simple example. In this example we will see how to Hello iPhone display using navigation base application.

Step 1: Create a Navigation Base application using template. Give the application name “HelloWorld_NavigationBase”.

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 RootViewController class for you (See the figure below). Expand Resources and notice the template generated a separate nib,RootViewController.xib, for the “HelloWorld_NavigationBase”.

Step 4: Open the RootViewController.m file, for this example we need to add only two lines of code in this file . So make the changes.

(void)viewDidLoad {
    [super viewDidLoad];

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
     self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

  (UITableViewCell *)tableView:(UITableView *)tableView   cellForRowAtIndexPath:(NSIndexPath *)indexPath {

   static NSString *CellIdentifier = @"Cell";

   UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
   cell = [[[UITableViewCell alloc]   initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]    autorelease];
}

  // Configure the cell. // added below two line
    [[cell textLabel] setTextAlignment:UITextAlignmentCenter];
    [cell.textLabel setText:@"Hello iPhone!"];

   return cell;
}

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

You can Download SourceCode from here HelloWorld_NavigationBase

Leave a Reply

Your email address will not be published. Required fields are marked *