简体   繁体   中英

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 *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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM