0

新手问题。是的,我已经查看了所有内容,但没有找到一个很好的解释来说明如何处理这个特定的实例。我确定这很简单,但我遇到了麻烦。如果您可以花 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];

}
4

1 回答 1

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 动画:YES];

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

于 2015-07-15T09:47:51.013 回答