TableView Controller:
.m :
//
// TableViewSample1ViewController.m
// TableViewSample1
//
// Created by training on 7/13/10.
// Copyright __MyCompanyName__ 2010. All rights reserved.
//
#import "TableViewSample1ViewController.h"
@implementation TableViewSample1ViewController
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
ns = [[NSMutableArray alloc] init];
NSInteger i;
for(i = 0; i < 20; i++)
{
[ns addObject : [NSString stringWithFormat: @"%d",i]];
}
[super viewDidLoad];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
#pragma mark Table View Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1; // number of sections
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [ns count]; // number of rows
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Sample statements
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tablecell"];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"tablecell"] autorelease];
#if 0
UILabel *name;
name =[[UILabel alloc] initWithFrame:CGRectMake(0, 0 ,185 , 20)];
[name setBackgroundColor:[UIColor clearColor]];
name.textAlignment = UITextAlignmentLeft;
name.textColor = [UIColor blueColor];
name.font = [UIFont systemFontOfSize:14];
[cell addSubview:name];
[name release];
#endif
}
// [cell setText:[ns objectAtIndex:indexPath.row]];
cell.textLabel.text = [ns objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath
{
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return @"Trip History"; // Table title
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 40.0; // table height
}
- (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.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[ns release];
[super dealloc];
}
@end