0

私のアプリケーションは別のマスター詳細を使用します。これは、tableView を持つ初期 ViewController で構成されていますが、ユーザーがナビゲーション コントローラーの [追加] ボタンをクリックすると、次の関数を使用してオブジェクトを送信する必要があります。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"AddDGV"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
        [[segue destinationViewController] setDetailView:object];
    }
}

宛先が別の ViewController の場合、コードは正常に動作しますが、私のアプリケーションは、ViewController の代わりに TabBarController を持つように設計されています。この TabBar には 2 つのタブがあり、それぞれに異なるナビゲーション コントローラーがあり、最初のタブは識別子 "AddDGV" のターゲットです。.m/.h ファイルを作成し、ストーリーボードでクラスを関連付け、インスタンス変数「DetailView」を ID として設定しました。

@property (strong, nonatomic) id detailItem;

問題は、コンパイラがこの変数を認識していないことです。これは、コマンド[segue destinationViewController]にビュー コントローラーが含まれており、その内容がセグエの最後に表示される必要があるためです。セグエの最後は TabBarController であるため、関数は機能しません。

誰かがそれを修正する方法を知っていますか???

4

1 に答える 1

0

の出力を型キャストする

[segue destinationViewController]

次のように

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"AddDGV"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
        [(YourDestinationViewController *)[segue destinationViewController] setDetailView:object];
    }
}
于 2013-04-19T03:03:38.147 に答える