如何显示自定义单元格中的图像到详细视图

问题描述:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath 
{ 


    TestViewController*detail = [self.storyboard instantiateViewControllerWithIdentifier:@"TestView"]; 


    [self.navigationController pushViewController:detail animated: YES]; 

    detail.outputLabel.text =[NSString stringWithFormat:[mutablearray1 objectAtIndex:indexPath.row]]; 
     // detail.outputImage.image =[NSString stringWithFormat:[mutablearray2 objectAtIndex:indexPath.row]]; 
} 
@end 

使用上面的代码我在tableview单元格中显示文本以详细视图。如何显示自定义单元格中的图像到详细视图

我也希望相应于详细视图的每一行,以显示图像。问题出在我知道的评论部分。

修改什么需要?

取消注释时,我得到了错误:终止应用程序由于未捕获的异常“NSInvalidArgumentException”,原因是:“ - [NSConcreteData getCharacters:范围:]:无法识别的选择发送到实例

+0

这通常是当u已经在解除对象。检查mutableArray2的内容是完整的 – 2011-12-21 11:40:44

我认为outputImage是的UIImageView对象。 我似乎在设置NSString对象而不是UIImage对象。请检查。

首先 我相信你应该将您的Push命令上方的[NSString stringWithFormat:[mutablearray1 objectAtIndex:indexPath.row]];移动。

我不明白你的问题标题和它的内容之间的关系。

BTW三 您正在使用 -

[NSString stringWithFormat:[mutablearray1 objectAtIndex:indexPath.row]]; 

不恰当。

当你想操作字符串您将使用[NSString stringWithFormat:] -

NSString * str1 = @"hellow"; 
    str1 = [NSString string with format:@"str1 %@",world]; 

当%@将由字的逗号后更换。 (还有更多,但我想给你一个基本的想法)。

如果你只是想传递一个字,你应该简单(我假设你的数组包含字符串!):

detail.outputLabel.text =[[mutablearray1 objectAtIndex:indexPath.row]; 

希望它可以帮助

+0

细explanation.I移动detail.outputLabel.text = [[mutablearray1 objectAtIndex:indexPath.row];以上推命令。但是,详细视图显示为空白。 – jason 2011-12-21 12:21:21

+0

它是初始状态吗? – shannoga 2011-12-21 12:58:39

+0

算出来。代码:[self.navigationController pushViewController:细节动画:YES]; detail.outputLabel.text = [mutablearray1 objectAtIndex:indexPath.row]; detail.outputImage.image = [[UIImage的页头] initWithData:[mutablearay2 objectAtIndex:indexPath.row]]; – jason 2011-12-21 14:26:33