JMeter Introduction for beginners…

What is Jmeter?

Apache JMeter is used as a load testing tool for analyzing and measuring the performance of a variety of services of web application.

Jmeter is a java based open source software tool.

JMeter can help you to do regression testing of your application by creating test scripts for web services.

JMeter runs in two modes:

  1. GUI mode (which runs on windows)
  2. Non-GUI mode (which runs on Linux)

 

Use of Jmeter?

JMeter can be used as a unit test tool for database connections, web services, etc.

Jmeter uses to test the load and performance of the web services.

Running Jmeter in GUI mode (which runs on windows)

Installation:

1. Install Java run time in your PC
url:- http://www.java.com/en/download/index.jsp

2. download Jmeter release.
url:- http://jmeter.apache.org/download_jmeter.cgi

3. Extract in your specify folder like as C://
run the file (C://jakarta-jmeter-x.x/bin/jmeter.bin)

Start the Jmeter interface, i.e. jMeter windows batch file from bin folder.

 

How to run JMeter?

Steps to run JMeter are as follows,

  1. Start JMeter windows batch file from bin folder, it will open interface as shown in below:Image
  2. Create your first test plan by creating thread group:Image
  3. Added Thread group:Image

Here thread group consists of 3 main properties,

a. Number of threads(users): It consists of number of requests you want to run in one test plan.

b. Ramp-up period (in seconds): It tells us how long all requests takes time to run. If there are multiple requests, then all requests get run one by one.

c. Loop count: It shows count that all requests get run in how many loops.

All samplers and listeners are involved in thread group.

4. Adding sampler:Image

Samplers describes that “Jmeter sends web requests to server and wait till response comes.”

5. Sampler (e.g: Http Request):Image

In this sampler, you can add parameters to send request to server to run the service.

6. Add listener:Image

Listener,  where test data and result get stored and it displays the output in different ways. Here added listener is “View as a tree”.

7. Run the test plan with result tree:

Now Select listener and run the test plan.Image

In this listener, output gets display in detail with,

a. Sample result: Where load time, sample count get displays to you.

b. Request: What request you send to server.

c. Response data: The exact output comes from server.

8. Run the test plan with result table: Here, table shows all results in tabular form with no. of requests and average time for all requests.Image

In this way your simple test plan of a web service get executed.

Consuming Webservices & Parsing JSON Response Tutorial :Part 2

Hi Folks,

This is the Part 2 of  Consuming Webservices & Parsing JSON Response Tutorial

Previously we have consumed webService using NSURLConnection and got the response successfully .

Now time to parse the JSON response and populate data on UITableView.So the question is Is There any external library to parse raw JSON string?

Yes, there is numbers of external JSON framework which makes developers job easy.For this tutorial we are going to use SBJson framework

You can grab this framework from here and if you have not read part 1 just go through it here

How to install JSON framework?

The simplest way to start using JSON in your application is to copy all the source files (the contents of the Classes folder) into your own Xcode project.

  1. In the Finder, navigate into the Classes folder.
  2. Select all the files and drag-and-drop them into your Xcode project.
  3. Tick the Copy items into destination group’s folder option.
  4. Use #import “SBJson.h” in your source files.

Parsing Raw JSON

The first thing you should do, if you do not understand exactly what’s going on, is to NSLog thedescription of the JSON parser output. This will be a “list” of NSDictionary and NSArray, and when you see the description output you will understand that there is a one-to-one mapping of JSON “object” to NSDictionary

I have created one method where my parsing logic goes

declare it in .h file

-(NSMutableArray *)parseJsonResponse:(NSString *)rawJsonResponse;

in .m file implement this method as

-(NSMutableArray *)parseJsonResponse:(NSString *)rawJsonResponse

{

NSArray *responseKeyValueArray;

NSError *error;

SBJSON *json = [[SBJSON new] autorelease];

NSDictionary *responseKeyValueDict = [json objectWithString:rawJsonResponse error:&error];

#if DEBUG

NSLog(@”JSON parsing responseKeyValueDict: %@”, responseKeyValueDict);

#endif

if (responseKeyValueDict == nil)


{

#if DEBUG

NSLog(@”JSON parsing failed: %@”, [error localizedDescription]);

#endif

}

else {

if([responseKeyValueDict  valueForKey:@”list”] )

{

responseKeyValueArray  =[responseKeyValueDict  valueForKey:@”list”];

#if DEBUG

NSLog(@”responseKeyValueArray ::%@”,responseKeyValueArray);

#endif

if ([responseKeyValueArray isKindOfClass:[NSArray class]])

{

NSMutableArray *artistdetails = [[NSMutableArray alloc]init];

for(int i=0;i<[responseKeyValueArray count];i++)

{

NSDictionary *keyValueIndex = [responseKeyValueArray objectAtIndex:i];

#if DEBUG

NSLog(@”keyValueIndex::%@”,keyValueIndex);

#endif

Artist *artist=[[Artist alloc]init];

artist.imageName=[keyValueIndex objectForKey:@”image”];

artist.artistName=[keyValueIndex objectForKey:@”name”];

#if DEBUG

NSLog(@”artist.artistName::%@”,artist.artistName);

#endif

[artistdetails addObject:artist];

[artist release];

}

#if DEBUG

NSLog(@”artistdetails %d”,[artistdetails count]);

#endif

return [artistdetails autorelease];

}

else

{

return nil;

}

}

}

return  nil;

}

Call this method in connectionDidFinishLoading .modify it as

– (void)connectionDidFinishLoading:(NSURLConnection *)connection

{

// do something with the data

// receivedData is declared as a method instance elsewhere

NSLog(@”Succeeded! Received %d bytes of data”,[receivedData length]);

NSString *responseString = [[[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding] autorelease];

NSLog(@”Succeeded! Received JSON String %@ “,responseString);

// parse raw json response

parsedResponseData=[self parsedJsonResponse:responseString];

// release the connection, and the data object

[connection release];

[receivedData release];

}

Now we have Artist information, populate data over UITableView.To achieve this reload tableview and modify you cell for row method as below.

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

{

static NSString *CellIdentifier = @”ArtistCell”;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

}

if([parsedResponseData count]!=0)

{

// Configure the cell.

Artist *a = [parsedResponseData objectAtIndex:indexPath.row];

NSLog(@”artist name isin cellfor index path %@”,a.artistName);

NSLog(@”artist image link is %@”,a.imageName);

cell.imageView.image=[self displayImage:a.imageName];

cell.textLabel.text=a.artistName;

}

else

{

if(indexPath.row==0)

{

cell.textLabel.text=@”No Data”;

}

}

return cell;

}

 

To display images to UIImage of table view cell add and implement one more method

-(UIImage*)displayImage:(NSString *)imageUrl

{

NSData* imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:imageUrl]];

UIImage* image = [[UIImage alloc] initWithData:imageData];

return image;

}

Done 🙂

Note:Although you might expect some UI Freeze while scrolling as there is no Lazy Loding of image.To resolve this just keep it your uitableview scroll disable.

Hit run and  output looks like this

 

Artist List

Your first Windows Store App

It is been a while Windows 8 is out, and being a techie, I was more than excited to use Windows 8. Yes, there are so many exciting features which include the Tiles, the Metro Interface! By the way I don’t think I am the only one who had a hard time getting used to the Start button as well as Settings button which is at the right pane or “Charm Bar!” 🙂

When overall UI is explored and observed, it was time to get into the actual Windows 8 App Development. Maybe it is my early days of development in Windows 8, but still, I found it interestingly amazing!

So, if the excitement is triggered above the limits, let us get started with your first app in Windows 8!

Prerequisites:

  • Microsoft Windows 8 (obviously!)
  • Microsoft Visual Studio 2012 with Developer License
    • Particularly, developer license is required to get the things going with Windows Store. It won’t allow you to develop any app unless you have the developer license.

So, when the prerequisites are finalized, let us develop the first “Hello World” app.

Steps to create your first Windows Store app:

  • Open Visual Studio 2012
  • Goto File Menu -> New -> Project..

You will be presented with the following screen

app1

Select Windows Store from Visual C#.

Out here, you have so many options for an app, for now, we will go for a Blank App (XAML)

  • Give a name for your app. Click Ok. You will be able to see a screen where App.xaml.cs is opened for you. This file, particularly, controls the whole operation of your app.
  • From the solution explorer, open the MainPage.xaml file. The following screen is displayed.

app2

As we have selected the blank app, you are able to see this blank “Slate”. You are able to design whatever you want from here.

  • Let us do some designing!From the toolbox, which is at the left pane, select a “Text Block”. If you’re an asp.net developer this is “label” for your understanding!  Drag and drop TextBlock.I always like to use the split view in Visual Studio, as you can see, if you’ve added the TextBlock, immediately changes in xaml code are also reflected. In quick succession, I assign the fontsize property to my TextBlock for making it appear a little big!

app3

  • So, in quick Succession, insert a button, which will be displaying a “Hello World” when clicked on it. The current TextBlock will be “My First Store App”.
  • Insert another TextBlock  and make it invisible.  So, finally you will be having the following screen.
    app4
  • Lets do some simple code.
    I just generate a click event for the button by double clicking on it, make another TextBlock visible to show our message, in the following code.
    One of the most crucial steps, which we often forget is to assign a TextBlock with “Name” property. Particularly, in Windows Store Apps, this particular step should not be missed.
    app5
  • The code:
    app6
    Note how the visibility property is used.
  • To see the result, click on the drop down arrow besides debug.
    app7
  • You can have a selection between a Simulator, Local Machine and Remote Machine.I prefer simulator. So, click on simulator to run your first app!It will build deploy and present you the app.First Screen:
    app8
    When clicked on “Click Me” button, you get presented with the following Screen
    app9

That’s the very first Hello World App you created for Windows Store!

Hope you liked it! 🙂

Introduction Of SEO : Part 1

Search engine optimization is collection of technique that allow your site to get more traffic  from search engine like Google, Microsoft Bing etc. SEO can be divided in to two main categories

  • On Page SEO (Website changes that makes on your site)
  • Off Page SEO (Works that takes place out of your site).

In this tutorial we will discuss brief about these method’s,

On Page SEO –

                On page SEO means the work take place on your web site which help’ s to get more traffic on your site from search engine.  On page SEO divided in following areas

  1. Title Tag – The most important part of your web page is title tag (<title></title>) because search engine crawl web sites day and night for taking the information and categories them so user can easily get what they are find or want. So make your title as clear as they have topic’s, so search engine clearly distinguish your pages from others.
  2. Header & Bold Tag – In web development generally HTML developer so many CSS for formatting topics of each page. It’s bad because while search engine crawl websites they simply ignore all CSS tags like <span> and etc.  instead of this use header tag i.e. <h1> to <h6> to  set topics of each page, while important topics put in to bold for user notifications.
  3. Keywords – While doing SEO for your site you must know which keyword or terms  you want to target. The SEO  keyword for site is divided in to three categories,
  • Specific keywords  e.g. – Black color shoes  etc.
  • Broad keywords e.g. – shoes, sports etc.
  • unique keywords  e.g. – unique identity of your site.

Off Page SEO –

                 Off page SEO is work that makes out of your site. The off page work is divided in following area

  1. Anchor Tag – Simply getting link from any other website or put your web site link on others web site is not enough to rank well in search engine but it’s depend on quality of your anchor text.
  2. Targeting Competitor – When you search for your competitor’s website, you will find out the most authoritative sites that mention your competitor. Visit these sites and try to get a link from those site’s. If  it is a review site, it may be as easy as sending a free product for review. If it is a forum or wiki, it may be just as easy as adding your link.

Don’t do this all at once, Make a note all of the sites you would like to get a link from, and slowly,  slowly acquire links from them. There is no set time period.

Consuming Webservices & Parsing JSON Response Tutorial :Part 1

Hi Folks ,

Today, I want to make a demonstration of fetching data from web servers by using NSURLConnection on objective-c platform.

What we are going to do?

We are going to create an application that will demonstrate you guys to make a GET  request with NSURLConnection. After that, the retrieved data will be shown in UiTableview .It would be basically my favorite Artist name and his image .

For this tutorial i am going to consume one WCF web service ,thanks to one of my colleague to helping me 🙂

API :http://182.72.47.242:49/RpManageCommon/GetArtistPhotos

Retrieved Data would be JSON format shown as below:

{"list":[{"image":"http:\/\/182.72.47.242:49\/images\/dy.png","name":"Dy"},{"image":"http:\/\/182.72.47.242:49\/images\/eminem.png","name":"Eminem"},{"image":"http:\/\/182.72.47.242:49\/images\/enrique.png","name":"Enrique"},{"image":"http:\/\/182.72.47.242:49\/images\/fiftycent.png","name":"Fiftycent"},{"image":"http:\/\/182.72.47.242:49\/images\/pitbull.png","name":"Pitbull"}]}

Now first of all create a new project on Xcode as a single view application. You may use any other of them however the project that I have started with was single view application.

Put UiTableView onto a xib, and make the bindings related to the view controller’s header file.

Open your view controller’s header class. In my example it is called “ViewController.h” and modify it as like as below.

import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

{

NSMutableData *receivedData;

}

@property (nonatomic, assign) IBOutlet UITableView *myTableView;

-(void)connectWebserviceSync;

@end

What we have done in here, we have created UITableView, and 1 NSMutableData object. One of the most important thing in here is that our view controller has implemented NSURLConnectionDataDelegate. Whenever our connection object start to fetching from a web page, if the delegate of our connection object is set to this view controller, it will call delegate methods to warn our view controller about the state of connection. Now let’s make some coding over view controller’s .m file.

First of all, I would like to implement the connectWebServiceSync method. Whenever  application will enter in ViewWillAppear Mode  it will call connectWebServiceSync method.

connectWebServiceSync  simply create NSURLConnection request and execute it.

Modify your .m as shown below

-(void)viewWillAppear:(BOOL)animated

{

//call webservice here

[self connectWebserviceSync];

}

-(void)connectWebserviceSync

{

// Create the request.

NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@”http://182.72.47.242:49/RpManageCommon/GetArtistPhotos”%5D

cachePolicy:NSURLRequestUseProtocolCachePolicy

timeoutInterval:60.0];

// create the connection with the request

// and start loading the data

NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

if (theConnection) {

// Create the NSMutableData to hold the received data.

// receivedData is an instance variable declared elsewhere.

receivedData = [[NSMutableData data] retain];

} else {

// Inform the user that the connection failed.

NSLog(@”connection failed”);

}

}

Here I create url, and afterwards a request with respect to instance of url. These are the same procedures for every requests

The tricky part , the delegation, comes into play at this time. The folks at Apple has created a simple way to deal with the states of connection by using delegation structure.There are actually lots of delegate methods in NSURLConnectionDataDelegate however, just only 3 of them is required to be implemented in class. Those are;

this method might be calling more than one times according to incoming data size

*/
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[receivedData appendData:data];
}
/*
if there is an error occured, this method will be called by connection
*/
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
NSLog(@”%@” , error);
}
/*
if data is successfully received, this method will be called by connection
*/
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
 NSString *responseString = [[[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding] autorelease];   NSLog(@”Succeeded! Received JSON String %@ “,responseString);
// release the connection, and the data object

    [connection release];

[receivedData release];

}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data this method is called more than ones if the data returned by server is huge. NSURLConnection is clever enough how to split and whenever it gets any kind of data it calls this method from bound delegate class.

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error this method is called if something is abnormally going on during the connection.

-(void)connectionDidFinishLoading:(NSURLConnection *)connection this method is called when connection finishes its job successfully. All the actions after fetching data from server can be done here. In our example, we have filled our data into our object “receivedData”. Now that, we can  convert our data into string with UTF8 encoding, and then can store it somewhere or Log it.

For this tutorial i just used NSLog to print json response.If you are implementing above code hit run and look into your console for output.

webservicedemo

What to do next?

We have Raw JSON string as a response.now we have to parse that raw JSON response and populate data over UITableView view

to be continued…..

UITableView Tutorial Part 3: ENABLING & CONFIGURING EDIT MODE

Hi Folks,

Hopes you are enjoying your weekend…

This is another tutorial related to UITableView,previously we have learned

1.Creating and using Simple tableView and populated data.

2. Creating UITableView using xib.

You can check Part 1 here and Part 2 here.

Some time you need to Edit your table view according to app .Let’s say you are dealing with some Music Player App, user must be able to delete songs from the list and thus UITableView requires Editing of Cells.

If you’re presenting data to your users in a tableView, it is very likely you would want to add & remove rows from the table. In order to do this, UITableViews have a BOOL property called isEditing, which you can use to enter & exit edit mode.

Edit Mode on a UITableView is configured through the

– (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath*)indexPath

and

– (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath

Swipe-to-delete will be enabled by default if a tableView can be edited.

methods of the UITableView DataSource Protocol.Add these two method to part 2 tutorial source code.

Enabling Edit Mode

Return YES for all IndexPath Sections / Rows you want Edit Mode enabled for.

– (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath*)indexPath

{

// Return YES

returnYES;

}

Configuring Edit Mode – The TableView:

The following code will affect how  existing ones deleted.

– (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath

{

if (editingStyle == UITableViewCellEditingStyleDelete) {

// Delete the row from the data source

[items removeObjectAtIndex:indexPath.row];

//reload Table view

[tableView reloadData];

}

Now hit run and swipe to delete the cell

Screen Shot 2013-01-27 at 3.10.01 PM

Screen Shot 2013-01-27 at 3.10.22 PMDone…Enjoy coding.. stay tune for more tutorial

UITableView Tutorial Part 2: Customizing Table View

Hi Folks,

Hope you have enjoyed my previous tutorial if not ,go and explore it here

This second part of UITableView tutorial is all about customizing Table View  using xib.Creating your own tableview cell could be such a hassle when you do it programmatically. To be able to follow this tutorial, you need to know how to add a tableview first. Refer to the previous tutorial on how to add a tableview if you still don’t know how to add it yet.

Let’s start!

1. Add a new file of subclass UITableViewCell.

UITableViewCell

2. After adding a new UITableViewCell class, only .h and .m files are created. So, let’s add another file, an empty Interface Builder Document (xib file). Name it with the same name with our .h and .m files (to avoid confusion).

choose templates

3. Drag a tableview cell to your xib file, and change its class to SampleTableCell (the one we added a while ago).

CustomClass

4. Start customizing your cell. Here in my example, I want to make a Top Artist Cell (One with profile pictures, & name)

    1. I changed the height of my cell to 90 (instead of the default cell height which is 44).
    2.  I added a UIImageView for the profile pictures.
    3. Added a UILabel for the name.

5. Make an IBOutlet property of the objects that might change dynamically. In our example, our profilePicture object may change dynamically, depends on who is on Top Artist Chart.  And remember to synthesize these objects.
//Inside .h file

@property (nonatomic, assign) IBOutlet UIImageView *picture;
@property (nonatomic, assign) IBOutlet UILabel *name;

//Inside .m file

@synthesize picture;
@synthesize name;
6. Connect these outlets to your objects in your xib file.

7. Create a new File, subclass of NSObject. This file will serve as our “Artist” object. This class must hold the important information we need, like the profilePicture filename, Name.
//Artist.h file

@interface Artist : NSObject
@property (nonatomic, strong) NSString *artistName;
@property (nonatomic, strong) NSString *imageName;
@end
//Artist.m file
@implementation User
@synthesize artistName;
@synthesize imageName;
@end

8. Create your Artist objects and put them all in your items Array.
//I created five Artist. Sample code…

    Artist *artist1 = [[Artist alloc] init];
    artist.artistName=@”Eminem”;
artist.imageName=@”eminem.png”;

//Put them all in our array list
items = [[NSArray alloc] initWithObjects: artist1, artist2, artist3, artist4, artist5, nil];
9. Before we proceed, change the cell’s Identifier . We need it later.One more thing add some Artist images in project

cell identifier

Remember the Datasource and Delegate methods of our tableView from the previous tutorial? We are going to modify/add some methods.

10. Remember that our customized cell’s height was changed to 90, right? It has become taller than the usual height of our tableViewCell. Add this method so that our tableView will know that the cell’s height was changed.
//If we did not change the height of our cell, we do not need to add this method.

– (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 90.0;
}

11. Lastly, modify this method cellForRow. This is the part where we tell the tableView that we will use our custom cell.

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @”ArtistCell”;
    SampleTableCell *cell = (SampleTableCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@”SampleTableCell” owner:self options:nil];
        for (id currentObject in topLevelObjects) {
            if ([currentObject isKindOfClass:[UITableViewCell class]]) {
                cell = (SampleTableCell *)currentObject;
                break;
            }
        }
    }
    // Configure the cell.

    Artist *artist = [items objectAtIndex:indexPath.row];

cell.picture.image= [UIImage imageNamed:artist.imageName];

cell.name.text = artist.artistName;

cell.selectionStyle = UITableViewCellSelectionStyleNone;

return cell;

}

12. Hit Run! check output as shown below

Runenjoy coding….stay tune

UITableView Tutorial Part 1: Introduction to iPhone TableView

Hi fellas

This 3 Part of UITableView Tutorial will take you that level where you can able to deal with creating,customizing, modifying ,Binding data and much more to the iPhone TableView.

So Let’s start..

Table view is commonly used to show lists of data. A table view is the view object that displays table’s data and instance of UITableView. Each visible row in a table view is implemented by UITableViewCell. Table views are not responsible for storing your table’s data. They store only enough data to draw the rows that are currently visible. Table views get their configuration data from an object that conforms to the UITableViewDelegate protocol and their row data from an object that conforms to the UITableViewDataSource protocol.

Follow the steps below to create UITableView sample:

1.Open Xcode and create new view based project named ‘MyTable’

2.Modify code in the MyFirstTableViewController.h file as follow:

 

#import <UIKit/UIKit.h>

@interface MyFirstTableViewController : UIViewController

<UITableViewDelegate,UITableViewDataSource>{

NSArray *listData;

}

@property(nonatomic, retain) NSArray *listData;

@end

3.Open MyFirstTableViewController.xib file and drag Table View from Library over to the View Window.

4.Connect tableview’s dataSource and delegate from connection inspector to File’s Owner.

5.Modify code in the MyFirstTableViewController.m file as follow:

 

#import “MyFirstTableViewController.h”

@implementation MyFirstTableViewController

@synthesize listData;

– (void)viewDidLoad {

NSArray *array = [[NSArray alloc] initWithObjects:@”iPhone”, @”iPod”,

@”iPad”,nil];

self.listData = array;

[array release];

[super viewDidLoad];

}

– (void)dealloc {

[listData dealloc];

[super dealloc];

}

#pragma mark –

#pragma mark Table View Data Source Methods

– (NSInteger)tableView:(UITableView *)tableView

numberOfRowsInSection:(NSInteger)section

{

return [self.listData count];

}

– (UITableViewCell *)tableView:(UITableView *)tableView

cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *SimpleTableIdentifier = @”SimpleTableIdentifier”;

UITableViewCell *cell = [tableView

dequeueReusableCellWithIdentifier:SimpleTableIdentifier];

if (cell == nil) {

cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault

reuseIdentifier:SimpleTableIdentifier] autorelease];

}

NSUInteger row = [indexPath row];

cell.textLabel.text = [listData objectAtIndex:row];

return cell;

}

@end

In viewDidLoad we are creating an array of data to pass to our Table View.
We have also added two more methods of data source delegate which are mandatory to implement when your implementing UITableViewDataSource delegate.

 

(NSInteger)tableView:(UITableView *)tableView

numberOfRowsInSection:(NSInteger)section

which specifies how many number of rows are there in one section of the Table View.
The default number  of section in Table View is one.

Another method is

 

  – (UITableViewCell *)tableView:(UITableView *)tableView

cellForRowAtIndexPath:(NSIndexPath *)indexPath

Which is called by table view when it needs to draw a row. This method is called n times and value of n is equal to value returned by first method. As this method is called once for every row,

 

if (cell == nil)

checks, if cell exits before, if not create new cell. Here ‘indexPath’ parameter gives us current Indexpath of the row from which we can get the current drawing row. Then we set the text of textLabel property of the current drawing cell and finally return the cell to the Table View.

 

Output will look like this:

uitableview