点击后退按钮时保存数据
我有一个简单的基于导航的应用程序,其中有一堆表单,我有一个连接到按钮的方法,该方法在点击按钮时保存数据,但我想知道当点击后退按钮时是否可以调用相同的方法导航?以防万一用户无法使用保存按钮。如果可以的话,我会怎样做呢?
提前致谢!
I have a simple navigation based app which has a bunch fo forms in it, I have a method connected to a button that saves data when the button is tapped but I was wondering if I could call the same method when the back button is tapped in the navigation? Just incase a user fails to use the save button. If it is possible, how would I go about it?
thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当按下后退按钮时(但也在其他时候),您的视图控制器的
viewWillDisappear:
方法将被调用,因此这可能是一个选项。但是,如果您呈现(例如)一个 modalViewController,或将另一个 viewController 推入导航堆栈,则也会调用
viewWillDisappear:
。我能想到的唯一方法是
-dealloc
方法,仅当控制器从导航堆栈中弹出时才会被调用。Your view controller's
viewWillDisappear:
method will be invoked when the back button is pressed (but also at other times), so that might be an option.However,
viewWillDisappear:
will also be invoked if you present (say) a modalViewController, or push another viewController onto the navigation stack.The only method I can think of that will be invoked only when the controller is popped from the navigation stack is the
-dealloc
method.当然,在 UIViewController 的
viewWillDisappear:
方法中。Sure, in the
viewWillDisappear:
method of the UIViewController.