Note that there are some explanatory texts on larger screens.

plurals
  1. POPageViewController: How to release ViewControllers added to it?
    primarykey
    data
    text
    <p>I have a problem with the new PageViewController (the one with the nifty page turn animations). As far as I understand, there is a stack of ViewControllers which you need to set up like so:</p> <pre><code>PageView *startingViewController = [self.modelController viewControllerAtIndex:0]; NSArray *viewControllers = [NSArray arrayWithObject:startingViewController]; [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL]; </code></pre> <p>So far so good. Then you need to set up a source (your model Controller). In your model controller, you need to have four methods:</p> <pre><code>-(PageView *)viewControllerAtIndex:(NSUInteger)index -(NSUInteger)indexOfViewController:(PageView *)viewController -(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController -(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController </code></pre> <p>The last two are called if you turn the page (to the next or the previous). The second one simply determines the page index number. The interesting one - and the one where my problem is - is the first one. The first one returns a ViewController (which in my example is called PageView). This is the very end of the method:</p> <pre><code>PageView *pView = [[PageView alloc] init]; return pView; </code></pre> <p>I am wondering where this pView ends up and how I can release it? I guess autorelease is a bad idea as I don't know how long it is needed. If it ends up in the stack (which I guess it does), how long is it needed? Surely just for the next couple of pages. For instance, imagine setting up a pView for page 1. You then turn to page 2 and 3. By then you don't need page 1 anymore - you could release it. If you go back to page 1 it will be reloaded.</p> <p>I put log commands in my pView dealloc, but it is never called. So I guess I'm leaking every single viewControllers I've created.</p> <p>Any ideas how and where to release them once they are not needed anymore?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload