search

Home  >  Q&A  >  body text

objective-c - iOS 开发如何实现 push 出来的 Controller 在 pop 回上一页面的时候不释放?

发现 QQ ,微信等在 Push 进 好友动态、朋友圈 这些页面的时候,总能保留在上一次进入时候最后浏览到的位置。这是如何实现的呢?

高洛峰高洛峰2889 days ago363

reply all(9)I'll reply

  • PHPz

    PHPz2017-04-18 09:20:36

    You only need to have a strong reference to the viewController

    
    @property (nonatomic, strong) FooViewController *viewController;
    
    ...
    
    - (void)push {
        if (!_viewController) {
            _viewController = [[FooViewController alloc] init];
        }
        [self.navigationController pushViewController:_viewController animated:YES];
    }
    

    In this way, after popping, the viewController still has a strong reference pointing to it and will not be cleared. The next time you push, you will still push to the viewController

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 09:20:36

    That should actually be cache

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:20:36

    The simplest thing is to make it a singleton. There is only one instance in the entire app life cycle. Create it once during initialization, and use it the rest of the time.

    reply
    0
  • 黄舟

    黄舟2017-04-18 09:20:36

    Can store page attributes, such as offsets and so on

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 09:20:36

    This is time limited, right? If you push to enter the page again in a short time, you will stay on the pop-out interface. You only need to judge the time difference between the time of exit and the time of re-entering. If the time difference is less than the time difference, the interface will pop up. If the time difference is greater than the time difference, the interface will be refreshed.

    reply
    0
  • 黄舟

    黄舟2017-04-18 09:20:36

    Just implement the push and pop methods yourself

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:20:36

    Write the next vc as an attribute and then push it

    reply
    0
  • PHPz

    PHPz2017-04-18 09:20:36

    Just don’t let the page be released

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:20:36

    There is only one thing like Moments in the APP, I think it is better to make it a singleton. After looking at it, when the network is disconnected, it shows that it is loading when I pull it up. When I go back and go back in, it still shows that it is loading. It feels like it is not released.
    And the data is also cached. After disconnecting from the Internet, killing the APP, and re-entering, the data refreshed before in the circle of friends can be seen

    reply
    0
  • Cancelreply