objective-c - iOS 开发如何实现 push 出来的 Controller 在 pop 回上一页面的时候不释放?
高洛峰
高洛峰 2017-04-18 09:18:36
0
9
357

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

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(9)
PHPzhong

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

刘奇

That should actually be cache

Ty80

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.

黄舟

Can store page attributes, such as offsets and so on

大家讲道理

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.

黄舟

Just implement the push and pop methods yourself

Peter_Zhu

Write the next vc as an attribute and then push it

PHPzhong

Just don’t let the page be released

洪涛

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template