0

こんにちは私は情報を転送するためにセグエコードの準備を追加しましたが、エラーが発生します。

タブバーコントローラーを持っています。4つのタブがあります。各タブには、ナビゲーションコントローラーと、ルートビューコントローラーとしてのVCがあります。

タブ1->navコントローラー->VC1からtab2-->navコントローラー--->VC1に値を取得する必要があります

(タブ2のnavコントローラーまたはタブ2のルートビューに接続されているセグエもあります)よろしくお願いします

error:customizableViewControllers]:認識されないセレクターがインスタンス0xf19bd60に送信されました(ただし、タブ2(インデックス1)に移動します)?私のエラーはどこにありますか?

    if ([segue.identifier isEqualToString:@"ResultsSegue"])

        {
//the root VC at tab 2
            ResultsIndexViewController*controller=[[ResultsIndexViewController alloc]init];

            UITabBarController *tabController = [segue destinationViewController];
            controller = (ResultsIndexViewController*)[[tabController customizableViewControllers]objectAtIndex:1];//crashing here
            controller.resultsArray=[NSMutableArray arrayWithArray:_matchedResultsArray];

        }
    }
4

1 に答える 1

1

コードのこの部分

 [1]   UITabBarController *tabController = [segue destinationViewController];
 [2]    controller = (ResultsIndexViewController*)[[tabController customizableViewControllers]objectAtIndex:1];//crashing here

誤解に満ちています。

UIViewController[1]では、destinationViewController(type )をtypeのオブジェクトに割り当てていますUITabBarController。これはコンパイラに合法です(UITabBarController継承するUIViewControllerため、両方ともタイプですUIViewController)が、実際に何が起こっているかを反映していません。あなたのセグエはになりますUIViewControllerまたはそれはUINavigationControllerです。

したがって、[2]行目で、tabControllerをタブバーコントローラーとして使用しようとすると、クラッシュします(1つではないため)。

プロジェクトを再設計する必要があります...Segueを忘れて、タブバーコントローラーを使用してください。何かのようなもの...

- (IBAction)moveToTab2:(id)sender {
    ResultsViewController* resultsVC = (ResultsViewController*)
                [[self.tabBarController viewControllers] objectAtIndex:1];
    resultsVC.resultsArray=
                [NSMutableArray arrayWithArray:_matchedResultsArray];
    [self.tabBarController setSelectedViewController:resultsVC;
}
于 2013-01-10T16:42:26.440 に答える