0

我有一个tableview单元格使用right detail layout. 我现在要做的是当用户选择一个单元格时。我应该向该单元格添加图像吗?

有什么建议我应该如何实施?

亲切的问候

4

4 回答 4

1

您可以这样做,-tableView:didSelectForRowAtIndexPath:即当用户选择您可以创建图像视图并添加它时

于 2013-03-04T11:03:16.673 回答
0

您没有提供任何有关您的图像保留位置的详细信息。

如果您的图像位于缓存目录中,那么您应该-didSelectRowAtIndexPath这样写...

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[[paths lastObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"Image-%d.png",indexPath.row]]];
yourImageView = [[UIImageView alloc] initWithImage:image];
[cell addSubView;yourImageView];

如果您从服务器下载图像,那么您的代码应如下所示:

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://yourURL.com"]]]; 
UIImage *image = [[UIImage alloc] initWithData:data];
yourImageView = [[UIImageView alloc] initWithImage:image];
[cell addSubView;yourImageView];

祝你好运 ...!!!

于 2013-03-04T11:20:59.053 回答
0

您可以创建 UITableViewCell 的子类。然后实现方法-touchBegin,做你需要的

于 2013-03-04T12:44:49.103 回答
0

尝试实现这个

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.imageView.image = [UIImage imageNamed:@"imageName"];
}
于 2013-03-04T11:33:00.920 回答