【发布时间】:2012-12-20 15:54:03
【问题描述】:
我的故事板包含一个导航控制器、一个表视图控制器和一个详细视图控制器。如何让详细视图控制器显示与 TableView 上选择的“单元格”相关的文本?
我目前设置了我的代码,因此如果选择了一个单元格,它将显示一个图像。就像如果选择了“单元格 1”,它将显示“图像 1”,如果选择了“单元格 2”,那么它将显示“图像 2”等。
- (void)viewDidLoad
{
[super viewDidLoad];
//Create a couple UIImage objects
UIImage *firstImage = [UIImage imageNamed:@"first.png"];
UIImage *secondImage = [UIImage imageNamed:@"second.png"];
UIImage *thirdImage = [UIImage imageNamed:@"third.png"];
//Title of the view
self.title = charName;
//UIImageview based on characterNumber
switch (characterNumber) {
case 0:
CharacterImage.image = firstImage;
break;
case 1:
CharacterImage.image = secondImage;
break;
case 2:
CharacterImage.image = thirdImage;
break;
default:
break;
}
}
除了文本而不是图像,我该怎么做?因此,当从 Table View Controller 中选择“Cell 1”时,它将导致带有可滚动文本的 DetailViewController,该文本与选择其他单元格时显示的文本不同。我会使用“UITextView”并上传不同的 .txt 文件吗?谢谢
因此,当从 Table View Controller 中选择“Cell 1”时,它将导致带有可滚动文本的 DetailViewController。
【问题讨论】:
-
文本源到底是什么?我的意思是,例如,您只想传递一个字符串并查看它?
-
是的,您可以使用 textviews 并根据 tableView 的单元格选择加载不同的文本。实际上,您可以制作包含标题的字典数组以显示在 tableView 单元格中以及该标题的详细信息。
-
在填充 tableView 单元格时,使用 [[dataArr objectAtIndex:indexPath.row]valueForKey:@"title"];并且当任何行被选中时传递描述 [[dataArr objectAtIndex:indexPath.row]valueForKey:@"title"];并在你的 textView 中显示该描述
-
@iVishal 所以我要替换 UIImage 的代码?因为这不是我需要的?
-
如果你的图片比较好..但是如果你不想使用图片来让你的构建更轻,那么你可以使用 textViews..
标签: iphone objective-c xcode cocoa-touch