当视图控制器即将在 iOS4 中弹出时得到通知 [英] Get notified when a view controller is about to be popped in iOS4

查看:53
本文介绍了当视图控制器即将在 iOS4 中弹出时得到通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题以前有人问过,但我能找到的答案是 2009 年的,不适合我的问题.让我重申一下这个问题.

我有一个 UINavigationController ,它生成并将许多不同的 UIViewController 推送到其堆栈上.其中之一是处理一些核心数据操作,当某个特定的 VC 从堆栈中弹出时需要保存这些操作.不要关注核心数据部分,它是关于弹出的.

I have a UINavigationController that spawns and pushes lots of different UIViewControllers onto its stack. One of those deals with some Core Data operations that need to be saved when that one particular VC get's popped off the stack. Don't focus on the Core Data part, it's about the popping.

如何在 UIViewController 将要从堆栈中弹出的那一刻进行挂钩?

How can I hook into the moment that the UIViewController is going to be popped off the stack?

  • 我希望有某种委托方法,但找不到.UINavigationControllerDelegate 协议非常稀疏.
  • 然后我开始考虑使用 viewWillDisappear,但是如果另一个视图被推入堆栈,它也会被调用,所以它不会没有提供合适的时机.
  • 这个回答问题,从 2009 年开始,选择查看 viewWillAppear 我们弹出"的视图控制器,但由于该调用没有对需要进行检查的 VC 的引用,这并不令人满意,并且会引入一种适得其反的依赖级别(VC 被多个 NC 使用).
  • 另一个已回答的问题,同样从 2009 年开始,选择继承 UINavigationController 并重写 popViewControllerAnimated: 方法.或者,也可以使用 VC 的 dealloc.我的直觉告诉我这不可能.
  • 最后是 2011 年 3 月的最后一个问题,但没有人愿意回答.
  • I was hoping for a delegate method of some sort, but couldn't find it. The UINavigationControllerDelegate protocol is very sparse.
  • I then started thinking of using viewWillDisappear, but that one is also called if another view is pushed onto the stack, so it doesn't provide the right moment.
  • This answered question, from 2009, opts to look at the viewWillAppear of the view controller that we're 'popping to', but since that call doesn't have a reference to the VC that needs to do the checking, this is unsatisfactory and will introduce a level of dependency that is counter productive (the VC is used by several NCs).
  • Another answered question, also from 2009, opts to subclass UINavigationController and rewrite the popViewControllerAnimated: method. Or alternatively use the VC's dealloc. My gut tells me that can't be the way to go.
  • Finally there's one last recent question from march 2011, but no one cared to answer it.

这让我处于目前不满意的心态.有没有人有更好的解决方案来找到 UIViewController 从 UINavigationController 的堆栈中弹出的时刻?

That leaves me in my current unsatisfied state of mind. Is there anyone out there with a better solution to finding the moment your UIViewController is popped off a UINavigationController's stack?

干杯,
EP.

推荐答案

viewWillDisappear 是合适的委托.如果您想确定 current 视图是 popped 还是 视图 ,则需要在此方法中添加逻辑>推.这里已经回答了 - viewWillDisappear:确定是否查看控制器正在弹出或正在显示子视图控制器

viewWillDisappear is the appropriate delegate. You will need to add logic within this method if you want to determine if the current view is being popped or a new view is being pushed. That's been answered here - viewWillDisappear: Determine whether view controller is being popped or is showing a sub-view controller

这篇关于当视图控制器即将在 iOS4 中弹出时得到通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆