处理视图上的内存警告,如果我重新加载,这些视图的行为将不会相同
我的程序的一部分根据从表视图中选择的提要来解析和 RSS 提要。
为了传递 rss 文件的 url,我正在创建一个新的视图控制器,并
setURL:(NSString*)url withTitle:(NSString*)title .....
在其上调用一个函数...(然后我推送它) 在该 viewController 的 viewDidLoad 中,我开始解析该 URL 等等。
现在,如果当此视图不可见时我收到内存警告。 (例如,我选择一篇文章继续并查看其摘要),我如何以一种方式发布此视图,以便我回来时可以取回相关表格? 我希望我说得清楚。我的问题是,如果视图控制器被释放,那么我就会丢失它应该解析的 URL。 当重新分配它时,viewDidLoad将尝试解析无效的url,我不禁想到会发生什么。 :|
我可以做什么来解决这个问题?我是否忽略此视图控制器上的内存警告,而只专注于释放其他视图控制器?
谢谢,我希望我能说清楚。
Part of my program parses and RSS feed depending on which feed was chosen from a tableview.
to pass the url of the rss file, i am creating a new view controller, and calling a function
setURL:(NSString*)url withTitle:(NSString*)title .....
on it... (then I push it)
in viewDidLoad of that viewController, i start the parsing for that URL and so on.
Now if i get a memory warning when this view isnt visible. (eg, i choose an article to go on and view it's summary), how can i release this view in a way that i can get back the relevant table when i come back?
I hope i'm being clear. my question is that if the viewcontroller is freed, then i lose the URL that it is supposed to parse.
When re-allocing it, the viewDidLoad will try to parse an invalid url, and i shudder to think what will happen. :|
What can i do to solve this problem? do i ignore the memory warning on this viewController, and just focus on freeing the other ones?
Thanks, and i hope I make myself clear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题不是很清楚。但是你的 viewcontroller 不应该在内存警告时被释放或释放,只有它的 view 属性被 ios 释放。
所以恕我直言,您将 url 存储在错误的位置。尝试将其存储在视图控制器上的 ivar 中,并将其设置在 init 方法中。这样,即使遇到内存警告,它也应该在整个视图控制器的生命周期中可用。
your question is not very clear. but your viewcontroller shouldn't be freed or dealloceted on a mem warning, only it's view property is being freed by ios.
So IMHO, you are storing the url in a wrong place..try storing it in an ivar on the view controller, and setting it on the init method. That way it should be available across the whole viewcontroller's life cycle even if a mem warning is encountered.