Hi. I have a simple UITableView. and i want to add a checkmark whenever i select a row. I have only one section in my table. could somebody plz help me with this.
SampleTable.h
@interface SampleTable : UITableView <UITableViewDelegate , UITableViewDataSource>
{
NSMutableArray *itemArray;
NSString *itemValue;
}
@property (nonatomic,retain) NSMutableArray *itemArray;
@property (nonatomic,retain) NSString *itemValue;
-(NSMutableArray *) displayItemArray;
@end
SampleTable.m
#import "SampleTable.h"
@implementation DropTableView
@synthesize itemArray,itemValue;
-(id)initWithFrame:(CGRect)frm
{
if(self=[super initWithFrame:frm])
{
[self displayItemArray];
self.delegate=self;
self.dataSource=self;
self.separatorStyle=UITableViewCellSeparatorStyleNone;
}
return self;
}
-(NSMutableArray *) displayItemArray {
if(itemArray==nil) {
itemArray=[[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",nil];
}
return itemArray;
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.itemArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
[cell autorelease];
}
[self flashScrollIndicators];
self.scrollEnabled=YES;
[self showsVerticalScrollIndicator];
cell.textLabel.text = [self.itemArray objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//stuff
}
-(void) dealloc
{
[itemValue release];
[itemArray release];
[super dealloc];
}
@end