Managing exclusive list in UITableView
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.
SampleTable.h
@interface SampleTable : UITableView <UITableViewDelegate , UITableViewDataSource>
{
NSMutableArray *itemArray;
NSString *itemV开发者_JS百科alue;
}
@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
See both links and then you will get a solution for this problem.
http://www.iphonedevsdk.com/forum/iphone-sdk-development/5112-checkbox-button-iphone-application.html
http://weheartgames.com/2009/06/simple-iphone-checkbox/
I hope it will help you.
精彩评论