2013-03-01 21 views
8

UIPageViewControllerが最初のコンテンツビューコントローラを永久に保持しているようです。たとえば :UIPageViewControllerメモリリーク

DataViewController *startingViewController = [self.modelController viewControllerAtIndex:0 storyboard:self.storyboard]; 
NSArray *viewControllers = @[startingViewController]; 
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL]; 
self.pageViewController.dataSource = self.modelController; 

startingViewControllerは、それが解放さpageViewController自体まで解放されることはありません。

このバグを再現するには、ページベースのアプリケーションテンプレートを使用してXCodeで新しいプロジェクトを作成します。そして

@property NSInteger debugIndex; // file scope 
NSLog(@"DataViewController[%d] created", self.debugIndex); // in viewDidLoad 
NSLog(@"DataViewController[%d] dealloc", self.debugIndex); // in dealloc 

DataViewController.m

へのコードの3行を追加します。そして、あなたは垂直方向にデモアプリケーションをスクロールするとき、あなたはこのようなログを取得します:

DataViewController[0] created 
DataViewController[1] created 
DataViewController[2] created 
DataViewController[1] dealloc 
DataViewController[3] created 
DataViewController[2] dealloc 
DataViewController[4] created 
DataViewController[3] dealloc 
DataViewController[5] created 
DataViewController[4] dealloc 
DataViewController[6] created 
DataViewController[5] dealloc 

DataViewController [0]ですが決して割り当て解除されません。

これについてのアイデアは? ありがとう!

+0

それを再利用あなたは今までにARCとこれに対する解決策を見つけますか? –

答えて

-1

私は同じ問題を抱えていたし、次のように解決:

[startingViewController release];初期のエンドポイント。

最初のViewControllerは割り当て解除されます。

+2

しかし、私はARCを使用しています... –

3

transitionStyle UIPageViewControllerTransitionStyleScrollを使用していますか?代わりにページカールアニメーションを使用すると消えるような、同じまたは同様の問題が発生しました。

私はUISliderBarにコンテンツ内の位置を設定させていたので、この問題は私のために複雑になりました。だから、UISliderBarの変更で、私はsetViewControllers:direction:animated:completion:を呼んでいました。これは、私のUIPageViewControllerで "stuck"を取得するコントローラの参照が増えています。

私もARCを使用しています。私はUIPageViewControllerに余分なView Controllerの参照を強制的に渡すための許容可能な方法を見つけられませんでした。私はおそらくページカールの遷移を使用するか、UIPcrollViewを使用して同等のUIPageViewControllerを実装してページングを有効にして、UIPageViewControllerの壊れたビューコントローラの管理に頼るのではなく、独自のビューコントローラキャッシュを管理できます。

+0

はい、私はスクロールスタイルを使用しています。私はオープンソースの実装のどれも私の要件を満たしていないので私自身のPageViewを実装しました。 –

3

まだ問題があるかどうかはわかりませんが、同じ問題があり、解決策が見つかりました。

理由はわかりませんが、動作します。

addChlidViewControllerの前ではなく、addSubviewの直後に最初のviewControllerを設定しています。

-(void)settingPageViewController{ 
if (!self.pageViewController) { 
    self.pageViewController = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil]; 
    self.pageViewController.delegate = self; 
    self.pageViewController.dataSource = self; 
    [self addChildViewController:self.pageViewController]; 
    [self.pageViewController didMoveToParentViewController:self]; 
    [self.containerView addSubview:self.pageViewController.view]; 
    [self.pageViewController setViewControllers:@[[self viewcontrollerAtIndex:0]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; 
}  
} 

となり、最初のviewControllerは適切なタイミングで解除されます。コールaddSubView

 [self.pageViewController setViewControllers:@[[self viewcontrollerAtIndex:0]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:^(BOOL finished){ 
     NSLog(@"finished : %d",finished); 
    }]; 

と終了ブロックが呼び出さない場合

も、私が見つかりました。

このブロックは最初のviewControllerがdeallocしなかった理由です。それはコールバック、そして答えを改善しなかった理由を

私は同様の問題に起こっていたかを把握するには、いくつかの試みの後

歓声

+0

これを受け入れる必要があります。 –

+0

はい、これは私のために働いた唯一の解決策です!ドキュメンテーションはこれを要件として述べていませんが、これは私にdeallocを呼び出させる唯一の方法でした。 –

1

を〜見つける行くよ、私は中にいることに気づきました私のプロジェクトには2つの理由があり、問題を残し、UIPageViewControllerを永遠に保持することになった。

1)が提示されたUIPageViewControllerとのUIViewControllerの間で循環参照(これは、両方のクラスに強いから弱いにプロパティを変更することにより、固定された)

2)であり、主な修正が

を変更することにありました私はこれが誰か

を役に立てば幸い

__weak __typeof__(self) weakSelf = self; 
    [weakSelf setViewControllers:@[initialDetailsViewController] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil]; 

[self setViewControllers:@[initialDetailsViewController] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil]; 

0

同じ問題がここに 私は変数 に私の最初のViewControllerを保つことによってそれを解決して、代わりに特定のpageIndexパラメータに同じVCを作成する私はちょうど

+0

あなたはコードスニペットで私を助けることができますか?前もって感謝します。 – Ashik

関連する問題