UITableView and Selecting Items
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"];
}
精彩评论