我正在使用带有自定义单元格的 tableView 我希望当用户选择任何行时它会在上面显示选定的图像这是代码但它不显示选定的图像
这是我为此 tableView 使用自定义单元格的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CustomCellIdentifier = @"CustomCellIdentifier";
cell = (RootCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"RootCell"
owner:self options:nil];
for(id oneObject in nib) {
if ([oneObject isKindOfClass:[RootCell class]]) {
cell = (RootCell *)oneObject;
cell.selectionStyle=UITableViewCellSelectionStyleNone;
}
}
}
if (indexPath.row == 0) {
cell.cellImageView.image=[UIImage imageNamed:@"ActivityF.png"];
} else if(indexPath.row==1) {
cell.cellImageView.image=[UIImage imageNamed:@"CatalogF.png"];
} else if(indexPath.row==2){
cell.cellImageView.image=[UIImage imageNamed:@"LibraryF.png"];
} else if(indexPath.row==3) {
cell.cellImageView.image=[UIImage imageNamed:@"CommunityF.png"];
} else if (indexPath.row==4) {
cell.cellImageView.image=[UIImage imageNamed:@"ReportsF.png"];
} else if (indexPath.row==5) {
cell.cellImageView.image=[UIImage imageNamed:@"PublishingF.png"];
} else if (indexPath.row==6) {
cell.cellImageView.image=[UIImage imageNamed:@"PostsF.png"];
} else {
cell.cellImageView=[UIImage imageNamed:@"7.png"];
}
UIImageView *separator = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"separatorline.png"]];
[cell.contentView addSubview: separator];
return cell;
self.tableView.backgroundColor = [UIColor colorWithRed:(149/255.f) green:(150/255.f) blue:(149/255.f) alpha:1.0f];
}
选择方法
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = indexPath.row;
[self.appDelegate.splitViewController viewWillDisappear:YES];
NSMutableArray *viewControllerArray=[[NSMutableArray alloc] initWithArray: [[self.appDelegate.splitViewController.viewControllers objectAtIndex:1] viewControllers]];
[viewControllerArray removeLastObject];
if (row == 0) {
self.firstDetailViewController=[[[FirstDetailViewController alloc] init]autorelease];
[viewControllerArray addObject:self.firstDetailViewController];
self.appDelegate.splitViewController.delegate = self.firstDetailViewController; }
if (row == 1) {
self.secondDetailViewController=[[[SecondDetailViewController alloc]init]autorelease];
[viewControllerArray addObject:self.secondDetailViewController];
self.appDelegate.splitViewController.delegate = self.secondDetailViewController;
}
if (row == 2) {
self.myLearningViewController=[[[MyLearningViewController alloc]init]autorelease];
[viewControllerArray addObject:self.myLearningViewController];
self.appDelegate.splitViewController.delegate = self.myLearningViewController;
}
}