Quote:
Originally Posted by pritamsaha
How to show data in table view?
|
include these two deligate in the header file
UITableViewDelegate,
UITableViewDataSource
#pragma mark Method to create TableView
-(void)createTableView
{
tabvTransaction=[[UITableView alloc] initWithFrame:CGRectMake(10,60,300,(5*50)+44) style:UITableViewStylePlain];
tabvTransaction.delegate = self;
tabvTransaction.dataSource = self;
tabvTransaction.scrollEnabled = YES;
tabvTransaction.autoresizesSubviews = YES;
tabvTransaction.showsVerticalScrollIndicator=YES;
tabvTransaction.backgroundColor=[UIColor clearColor];
[self.view addSubview:tabvTransaction];
}
#pragma mark tableView Delegate Methods
- (NSInteger)numberOfSectionsInTableView: (UITableView *)tableView
{
NSLog(@"appATM.arrTransactionList=%d",[appATM.arrTransactionList count]);
return [appATM.arrTransactionList count];
}
- (NSInteger)tableView: (UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
static NSString *CellIdentifier1 = @"Cell1";
UITableViewCell *cell;
if(cell==nil)
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier1] autorelease];
}
cell.selectionStyle=UITableViewCellSelectionStyleN one;
UIImageView *imgv=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"white_strip.png"]];
cell.backgroundView=imgv;
[imgv release];
UILabel *lbl1=[tool createLabelWithFrame:CGRectMake(10, 0, 120, 25) ContainedIn:cell.contentView ofBackColor:[UIColor clearColor] ofTextColor:[UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0] ofLines:1 ofFont:[UIFont fontWithName:@"Verdana" size:12] ofText

(Transaction *)[appATM.arrTransactionList objectAtIndex:indexPath.section]).strDate ofAlignment:UITextAlignmentLeft];
[lbl1 release];
UILabel *lbl2=[tool createLabelWithFrame:CGRectMake(250, 0, 50, 30) ContainedIn:cell.contentView ofBackColor:[UIColor clearColor] ofTextColor:[UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0] ofLines:1 ofFont:[UIFont fontWithName:@"Verdana" size:12] ofText

(Transaction *)[appATM.arrTransactionList objectAtIndex:indexPath.section]).strAmount ofAlignment:UITextAlignmentLeft];
[lbl2 release];
UILabel *lbl3=[tool createLabelWithFrame:CGRectMake(10, 20, 120, 30) ContainedIn:cell.contentView ofBackColor:[UIColor clearColor] ofTextColor:[UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0] ofLines:1 ofFont:[UIFont fontWithName:@"Verdana" size:12] ofText

(Transaction *)[appATM.arrTransactionList objectAtIndex:indexPath.section]).strCard ofAlignment:UITextAlignmentLeft];
[lbl3 release];
return cell;
}
- (CGFloat)tableView: (UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *)indexPath
{
return 50;
}
- (UIView *)tableView: (UITableView *)tableView viewForHeaderInSection: (NSInteger)section
{
if(section==0)
{
localView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 22)];
CGRect frame = CGRectMake(0, 0, 300, 22);
UIImageView *imgvLocal=[[UIImageView alloc]initWithFrame:frame];
imgvLocal.image=[UIImage imageNamed:@"Top-Strip-300x20.png"];
[localView addSubview:imgvLocal];
[imgvLocal release];
return localView;
}
return nil;
}
- (UIView *)tableView: (UITableView *)tableView viewForFooterInSection: (NSInteger)section
{
if(section==([appATM.arrTransactionList count]-1))
{
CGRect frame = CGRectMake(0, 0, 300, 22);
localView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 22)];
UIImageView *imgvLocal=[[UIImageView alloc]initWithFrame:frame];
imgvLocal.image=[UIImage imageNamed:@"Bottom-Strip-300x20.png"];
[localView addSubview:imgvLocal];
[imgvLocal release];
return localView;
}
return nil;
}