UITableView and Selecting Items

后端 未结 1 1164
栀梦
栀梦 2021-01-29 12:38

I am currently creating a simple grouped UITableView that when the user selects for example \"Apple\" I would like a image I have in my project to be loaded into a Image View of

相关标签:
1条回答
  • 2021-01-29 13:06

    Either set the cell.imageView.highlightedImage, or in the didSelectRowAtIndexPath method, change the cell.imageView.image from nil to some [UIImage imageNamed:@"myImage.png"]:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *kCustomCellID = @"com.me.foo.cell";
        UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCustomCellID] autorelease];
        cell.textLabel.highlightedTextColor = [UIColor blueColor];
        cell.imageView.image = nil;
        cell.imageView.highlightedImage = [UIImage imageNamed:@"myImage.png"];
        return cell;
    }
    
    - (void)tableView:(UITableView *)tableView willDisplayCell:(iPadRootViewControllerTableCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
        cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        // Do this if you didnt set the highlightedImage in cellForRowAtIndexPath
        // [self tableView:tableView cellForRowAtIndexPath:indexPath].imageView.image = [UIImage imageNamed:@"myApple.png"];
    }
    
    0 讨论(0)
提交回复
热议问题