iPhone:如何允许在tabelview多个select自定义单元格?

我怎样才能适应这个能够做出多种select? 并获得选定的

- (id)initWithCellIdentifier:(NSString *)cellID { if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID])) { UITableViewCell *cell=self; UIImage *cry = [UIImage APP_CRYSTAL_SELECT]; self.leftImage = [[[UIImageView alloc] initWithImage:cry] autorelease] ; [self.contentView addSubview:leftImage]; } 

而select的方法是:

 - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; if(selected) { NSArray *subviews=[self.contentView subviews]; for(UIView* view in subviews){ if([view isEqual:self.leftImage]){ [self.leftImage setHighlightedImage:[UIImage APP_CRYSTAL_SELECTED]]; } } } else { NSArray *subviews=[self.contentView subviews]; for(UIView* view in subviews){ if([view isEqual:self.leftImage]){ [self.leftImage setHighlightedImage:[UIImage APP_CRYSTAL_SELECT]]; } } } } 

对于多选,设置一个NSMutableArray伊娃(在这种情况下是selectedIndexPaths)来保存选中的项目。 在didSelectRowAtIndexPath添加或删除索引到这个数组。

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(![self.selectedIndexPaths containsObject:indexPath]) [self.selectedIndexPaths addObject:indexPath]; else [self.selectedIndexPaths removeObject:indexPath]; } 

稍后使用selectedIndexPaths来做任何你想做的事情! 干杯!

-Akshay