how to display records in tableview using ios programming?

Leave a Comment
This is very simple basic application that will display records in table view in iphone using ios programming.
Here complete explanation of display records in grid form using tableview in iphone. by step wise we will see this such a good tutorial.

Step 1:
just select single view application.

 Step 2:
give name of application simple table view application
 Step 3: this is the Application settings for it.
 Step 4:
Just drag table view from object library to your xib file view.
step 5: Now declare NSArray in header file.
 Step 6: Now in implementation file just initialize data.


Step 7:
here i am implementing two methods :
1]number of rows in section which will return count of  rows

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [data count];
}

2]cellforrowatindexpath method will be called in every time when records are binding in tableview

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableData";
 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
 
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }
 
    cell.textLabel.text = [data objectAtIndex:indexPath.row];
    return cell;
}
here i am giving this code snippest for both methods..



Step 8:
Now run your application still it will not showing any records in tableview.

 Step 9:
 select tableview and press ctrl ker and dragging line to file's responder so it will give you like this pop up for delegate and datasource . so select both for tableview.

Step 10:
Now run your application and it will show you complete records in tableview.

devangViewController.h

#import <UIKit/UIKit.h>
@interface devangViewController : UIViewController
@property (weak,readonly) NSArray *data;
@end

  devangViewController.m

#import "devangViewController.h"
@interface devangViewController ()
@end
@implementation devangViewController
@synthesize data;
- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
 
    data = [NSArray arrayWithObjects:@"devang9978@gmail.com", @"www.studyoverflow.org",@"www.techstudy.net" , @"devang9978@gmail.com", @"www.studyoverflow.org",@"www.techstudy.net" ,@"devang9978@gmail.com", @"www.studyoverflow.org",@"www.techstudy.net" ,@"devang9978@gmail.com", @"www.studyoverflow.org",@"www.techstudy.net" ,nil];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [data count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableData";
 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
 
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }
 
    cell.textLabel.text = [data objectAtIndex:indexPath.row];
    return cell;
}
@end

I hope you will get complete tutorial still you need any help please mail me on devang9978@gmail.com or leave comment..(BY www.techstudy.net)






0 comments:

Post a Comment