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委托方法,并在单击单元格时调用该方法