【发布时间】:2012-10-02 02:33:40
【问题描述】:
新手问题。是的,我已经查看了所有内容,但没有找到一个很好的解释来说明如何处理这个特定的实例。我确定这很简单,但我遇到了麻烦。如果您能花 5 分钟时间查看代码并帮助我理解,那就太好了。
好的,我有一个名为 •cell 的自定义单元格,我已经给出了“MyCell”的标识符。这充满了细节并且工作正常。问题是当我尝试将其传递给详细视图时。我正在努力理解传递它的最佳方法,特别是如何从我的自定义单元格的一部分获取文本并在 detailView 中复制它 - 文本标签是否意味着在自定义单元格中被称为与它相同是在detailView还是别的什么?我知道我需要在 didSelectRowAtIndexPath 中添加一些内容,但我不确定如何构建它。
我的 detailViewController 被称为 detailViewController 并在标识符中给出了身份 detailViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// I've called this •cell but my custom cell is called MyCell in the identifier - I'm not sure if this makes a difference?
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//then I craete my detailViewController
UIViewController *detailViewController = [[UIViewController alloc] initWithNibName:@"detailViewController" bundle:nil]; // ...
//I think I understand this bit - detailTitle is the name I have given to the text label in the detail view and venueHeader is the name of the corresponding label in the custom cell - I want the detailTitle to = venueHeader
detailViewController.detailTitle = CustomCell.venueHeader.text;
// I have created a segue in storyboards so I don't know if I need this bit of code as well?
[self.navigationController pushViewController:detailViewController animated:YES];
}
【问题讨论】:
-
单元格的内容是什么??
-
嗨 Jossef - 只有 4x 文本标签
-
您是否正在将可重复使用的单元格出列?这是您使用的实际代码吗?您是否为自定义单元格创建了 UITableViewCell xib 文件?
-
是的。我正在为我的自定义单元使用单元原型 - 所有这些部分都工作正常。只是环顾四周,我是否更好地使用 prepareForSegue 将数据从表传递到详细视图?
标签: ios xcode uitableview custom-cell detailview