ARTICLE

Static Table Using StoryBoard in iPhone

Posted by Sachin Bhardwaj Articles | iPhone/iPad December 01, 2012
In this article I will explain how to create a static table using a storyboard in iPhone.
Reader Level:
Download Files:
 

Introduction

In this article I will create an Empty view application. Here I use a Grouped table from an outlet and set four labels and an image view on it. Here we add a storyboard from a resource.

To understand it we use the following procedure.

Step 1

Initially we add a storyboardViewController Class of the UITableViewController type.

To add a UITableViewController Objective-C Class we use the following:

new-file-in-iphone.jpg

Select the App delegate class and right-click on it to add a new file.

objective-c-class-in-iphone.jpg
Select Objective-C Class and Click on Next.

storyboardViewController-Class-in-iphone.jpg

Now Select UITableViewController Class without Xib and click on Next. 

objective-c-class-save-location-in-iphone.jpg

Now Click on Create to import it to the project.

Step 2

Now we add a storyboard Class. To add a storyboard we use the following:

add-new-file-in-iphone.jpg

Select Storyboard class and right-click on it to add a new file.

click-on-storyboard-in-iphone.jpg

Select User Interface Storyboard and click on Next.

select-device-family-in-iphone.jpg

Now select device family and click on Next.

save-location-in-iphone.jpg

Click on Create.

Step 3

Here we write the code.

storyboardViewController.h

#import <UIKit/UIKit.h>


@interface storyboardViewController : UITableViewController

@property (strong, nonatomic) IBOutlet UILabel *NameLabel;

@property (strong, nonatomic) IBOutlet UILabel *DesignationLabel;

@property (strong, nonatomic) IBOutlet UIImageView *ImageView;


@end

storyboardViewController.m

#import "storyboardViewController.h"

@interface storyboardViewController ()

@end

@implementation storyboardViewController

@synthesize NameLabel;

@synthesize DesignationLabel;

@synthesize ImageView;

- (id)initWithStyle:(UITableViewStyle)style

{

    self = [super initWithStyle:style];

    if (self) {

        // Custom initialization

    }

    return self;

}

- (void)didReceiveMemoryWarning

{

    // Releases the view if it doesn't have a superview.

    [super didReceiveMemoryWarning];

      // Release any cached data, images, etc that aren't in use.

}

#pragma mark - View lifecycle

- (void)viewDidLoad

{

    [super viewDidLoad];

    self.NameLabel.text = @"Sachin";

    self.DesignationLabel.text = @"iPhone Developer";

    self.ImageView.image = [UIImage imageNamed: @"image1.jpeg"];

}

#pragma mark - Table view data source

- (void)viewDidAppear:(BOOL)animated

{

    [super viewDidAppear:animated];

}

- (void)viewWillDisappear:(BOOL)animated

{

    [super viewWillDisappear:animated];

}

- (void)viewDidDisappear:(BOOL)animated

{

    [super viewDidDisappear:animated];

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

   // Return YES for supported orientations

    return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

#pragma mark - Table view data source

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    // Navigation logic may go here. Create and push another view controller.

    /*

     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];

     // ...

     // Pass the selected object to the new view controller.

     [self.navigationController pushViewController:detailViewController animated:YES];

     */

}

@end

Storyboary.storyboard

storyboard-in-iphone.jpg

Step 4

Select table style -> Grouped

select-table-style-in-iphone.jpg

Step 5

Select Table View Section and Set Header Footer

select-header-footer-in-iphone.jpg

Step 6

Now we click on Storyboard TableViewController Class and Check all Connections and perform the linking.

connection-in-iphone.jpg

Step 7

Now run the application and see the output.

Output

output1-in-iphone.jpg

Before Scroll down

output2-in-iphone.jpg

After scroll Down.

Login to add your contents and source code to this article
comments
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter