UITableView和选择项目 [英] UITableView and Selecting Items

查看:85
本文介绍了UITableView和选择项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在创建一个简单的分组UITableView,当用户选择例如Apple时,我希望我的项目中的图像被加载到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 internet but I am trying to see what else is out there.

任何建议都将不胜感激。谢谢。

Any suggestions would be greatly appreciated. Thanks.

推荐答案

设置 cell.imageView.highlightedImage ,或者在 didSelectRowAtIndexPath 方法中,将 cell.imageView.image 从nil更改为某些 [UIImage imageNamed:@myImage.png]

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"];
}

这篇关于UITableView和选择项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆