2

我正在使用故事板和转场。我想从“联系人列表”(tableView)切换到“个人资料视图”(ScrollView)。

三个问题

  • 这是做到这一点的最佳方式(更干净、更漂亮)吗?& 为什么 ?
  • 当我这样做时: ProfileViewController *aProfileView = (ProfileViewController *)[segue destinationViewController]; 这是实例化一个新视图吗?(就像它会创建 2 个配置文件视图)。
  • 我需要清理(删除某处的“个人资料视图”吗?)还是单独使用导航控制器进行清理?

// 代码

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showProfileSelected"]) 
    {
        // Get the Selected raw
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        Profile *selectedProfile = [self.profilesTable objectAtIndex:indexPath.row];

        // Using segue --> Send the current selected profile to "ProfileView"
        ProfileViewController *aProfileView = (ProfileViewController *)[segue destinationViewController];
        aProfileView.currentProfile = selectedProfile;
    }
}

// 其他方法:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showProfileSelected"]) 
    {
        // Get the Selected raw
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        Profile *selectedProfile = [self.profilesTable objectAtIndex:indexPath.row];

        // Using segue --> Send the current selected profile to "ProfileView"
        [segue.destinationViewController setCurrentProfile:selectedProfile];
    }
}
4

1 回答 1

1

你的第一个例子很好。您没有创建任何东西,只是获取对目标控制器的引用。设置这样的变量允许您在目标视图控制器上设置多个属性,而无需一遍又一遍地进行转换。

因此,要回答您的具体问题:

  • 是的,这是最好的方法。由于目标视图控制器的通用类,很难让 prepareForSegue “漂亮”
  • 不,你没有创造任何东西。
  • 不,你没有什么要清理的。
于 2012-05-21T06:12:24.083 回答