1

私のアプリの1つでは、通常の左から右ではなく、右から左にUINavigationControllerプッシュするためにサブクラスを使用しています。ViewControllersこれを実現するために、次のコードを使用して pop と push アニメーションを置き換えています。iOS 7 より前のすべての iOS でうまく機能しています。

私のコードの関連部分は次のとおりです。

UINavigationController サブクラス:

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    // Add the viewController and a fake controller without animation. Then pop the fake controller with animation.
    UIViewController *fakeController = [[UIViewController alloc] init];
    [super setViewControllers:[[self viewControllers] arrayByAddingObjectsFromArray:[NSArray arrayWithObjects:viewController, fakeController, nil]] animated:NO];
    NSLog(@"Log1: %d",[self.viewControllers count]);
    [super popViewControllerAnimated:animated];
    NSLog(@"Log2: %d",[self.viewControllers count]);
    [self performSelector:@selector(test) withObject:Nil afterDelay:5];
}

-(void)test
{
      NSLog(@"Log3: %d",[self.viewControllers count]);
}

iOS 6 以下では、ログに次のように表示されます。

Log1:3
Log2:2
Log3:2

iOS 7 では、ログに次のように表示されます。

Log1:3
Log2:2
Log3:1 //<---This is my problem

iOS 7 が原因でこれが発生していることをさらに確認するために、3 つの空の Viewcontrollers とサブクラスUINavigationController化された上記のメソッドを含む新しいプロジェクトを作成しました。iOS 7 と iOS 6 ではまだ異なる結果が得られます。

配列の最初ViewControllerのものも削除されるのはなぜですか? どうすれば修正できますか?

4

0 に答える 0