2011-12-21 42 views
0
- (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

回答

0

我認爲outputImage是的UIImageView對象。 我似乎在設置NSString對象而不是UIImage對象。請檢查。

1

首先 我相信你應該將您的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

相關問題