将详细信息从tableView中的自定义单元格传递到detailView

时间:2012-10-11 12:19:32

标签: ios xcode uitableview custom-cell detailview

新手问题。是的,我看了很多,但没有找到对这个特定实例做什么的好解释。我确信这很简单,但我遇到了麻烦。如果您可以花5分钟时间查看代码并帮助我理解这将是非常好的。

好的,我有一个名为•cell的自定义单元格,我已经给出了'MyCell'的标识符。这充满了细节,工作正常。问题是当我尝试将其传递给详细视图时。我正在努力理解传递这个的最佳方法,特别是如何从我的自定义单元格的一部分获取文本并在detailView中复制 - 是文本标签在自定义单元格中被称为相同的文本标签在detailView或其他东西?我知道我需要在didSelectRowAtIndexPath中添加一些内容,但我不确定如何构建它。

我的detailViewController被称为detailViewController,并在标识符

中给出了identityViewController
- (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];

}

1 个答案:

答案 0 :(得分:0)

您可以使用此代码

 UIStoryboard *storyBoard=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
DetailViewController *pvc=[storyBoard instantiateViewControllerWithIdentifier:@"DetailViewController"];
pvc.dict = [arrData objectAtIndex:indexPath.row];
 pvc.upload  = [arrData1 objectAtIndex:indexPath.row];

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

比目标视图控制器中的打印字典后获取数据

相关问题