2

ストーリーボードとセグエを使用しています。「連絡先リスト」(tableView) から「プロフィール ビュー」(ScrollView) に切り替えたい。

3 つの質問:

  • これはこれを行うための最良の方法(よりクリーンで美しい)ですか?& どうして ?
  • 私がこれを行うとき: 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

最初の例は問題ありません。何も作成しておらず、宛先コントローラーへの参照を取得しているだけです。このような変数を設定すると、何度もキャストしなくても、宛先のViewControllerに複数のプロパティを設定できます。

だから、あなたの特定の質問に答えるために:

  • はい、それが最善の方法です。デスティネーションビューコントローラのジェネリッククラスのため、prepareForSegueを「美しく」することは困難です
  • いいえ、何も作成していません。
  • いいえ、クリーンアップするものはありません。
于 2012-05-21T06:12:24.083 に答える