开发者

UITableView and Selecting Items

开发者 https://www.devze.com 2023-04-05 06:39 出处:网络
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 a Apple.

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 a Apple.

I have seen some examples on the inter开发者_如何学Gonet but I am trying to see what else is out there.

Any suggestions would be greatly appreciated. Thanks.


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

精彩评论

暂无评论...
验证码 换一张
取 消