Static Table Using StoryBoard in iPhone

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.


Similar Articles