Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在选择时更改UITableViewCell布局_Iphone_Ios_Objective C_Uitableview - Fatal编程技术网

Iphone 在选择时更改UITableViewCell布局

Iphone 在选择时更改UITableViewCell布局,iphone,ios,objective-c,uitableview,Iphone,Ios,Objective C,Uitableview,我有一个表格视图,其中单元格使用右侧详细布局。我现在想做的是当用户选择一个单元格时。我应该给那个单元格添加一个图像吗 有什么建议我应该如何实施 亲切问候您可以在-tableView:didSelectForRowAtIndexPath:中执行此操作,即当用户选择时,您可以创建一个图像视图并添加它您没有给出有关图像保留位置的任何详细信息 如果图像位于缓存目录,那么您应该像这样编写-didSelectRowAtIndexPath NSArray *paths = NSSearchPathForDir

我有一个
表格视图
,其中单元格使用
右侧详细布局
。我现在想做的是当用户选择一个单元格时。我应该给那个单元格添加一个图像吗

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


亲切问候

您可以在
-tableView:didSelectForRowAtIndexPath:
中执行此操作,即当用户选择时,您可以创建一个图像视图并添加它

您没有给出有关图像保留位置的任何详细信息

如果图像位于缓存目录,那么您应该像这样编写
-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];
祝你好运

尝试实现此功能

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

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.imageView.image = [UIImage imageNamed:@"imageName"];
}

您可以创建UITableViewCell的子类。
然后实现method-touchBegin,您是否需要

发布codecreate委托方法,并在单击单元格时调用该方法