0

次のコードを使用して、navigationcontroller(viewcontrollers) からログイン ページを削除し、戻る (戻るボタン) ときに再びビューに表示されないようにしました。

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
    NSMutableArray *VCs = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
    if([[VCs objectAtIndex:[VCs count] - 2] isKindOfClass:[loginViewController class]]&&(VCs.count>=4))
    {
        [VCs removeObjectAtIndex:[VCs count] - 2];
        [VCs removeObjectAtIndex:[VCs count] - 2];
        [self.navigationController setViewControllers: VCs];
    }
}

これはiPhoneで完璧に機能します。しかし、iPad の場合、splitViewController を使用しているため、次のようにコーディングすると

NSMutableArray *VCs = [NSMutableArray arrayWithArray:self.splitViewController.viewControllers];

得られるのは、navigationControllers の配列です。splitviewcontroller から特定の viewcontroller を削除できる本物のロジックはありますか?

4

1 に答える 1

2

あなたが言ったように、分割ビューコントローラーは、ナビゲーションコントローラーの配列を返します(プロジェクトの設定によって異なります)。それらへの参照を取得したら、必要に応じてそれらを操作できます。

UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *masterNavVC = (UINavigationController *)splitViewController.viewControllers.firstObject;
UINavigationController *detailNavVC = (UINavigationController *)splitViewController.viewControllers.lastObject;

//Now you have the master and detail navigation controllers, get your VC you need to manipulate
NSMutableArray *masterVCs = masterNavVC.viewControllers;
NSMutableArray *detailVCs = detailNavVC.viewControllers;

//Remove the ones you need to - this example is arbitrary. Put your logic here
if(masterVCs.count > 0 && [masterVCs[0] isKindOfClass:[LoginViewController class]])
{
     //Remove or add
}
于 2015-03-11T13:48:30.047 に答える