PageViewController: How to release ViewControllers added to it?

后端 未结 1 1815
花落未央
花落未央 2021-01-06 18:55

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

相关标签:
1条回答
  • 2021-01-06 19:28

    autorelease is exactly what you need. This is the perfect situation for which autorelease was designed i.e. you need to return an object but don't know how long it will be needed.

    PageView *pView = [[PageView alloc] init] autorelease];
    return pView;
    

    Your PageView instance is allocated on the heap (not the stack) and PageViewController will take ownership of it and retain it if it needs to keep it around. It becomes PageViewController's responsibility after your method has returned.

    (Otherwise just use ARC and let the compiler take care of it)

    0 讨论(0)
提交回复
热议问题