我正在使用情节提要和转场。我想从“联系人列表”(tableView)切换到“个人资料视图”(ScrollView)。
三个问题 :
- 这是最好的方法(更干净和漂亮)吗?& 为什么 ?
- 当我这样做时: ProfileViewController *aProfileView = (ProfileViewController *)[segue destinationViewController];这是实例化一个新视图吗? (就像它会创建 2 个配置文件视图一样)。
- 我是否需要清理(删除某处的“配置文件视图”?)或者它单独与导航控制器一起执行?
// Code
- (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];
}
}
你的第一个例子很好。您没有创建任何东西,只是获取对目标控制器的引用。设置这样的变量允许您在目标视图控制器上设置多个属性,而无需一遍又一遍地进行转换。
因此,回答您的具体问题:
- 是的,这是最好的方法。由于目标视图控制器的通用类,很难让prepareForSegue变得“漂亮”
- 不,你没有创造任何东西。
- 不,你没有任何东西需要清理。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)