Find out if user pressed the back button in uinavigationcontroller?

后端 未结 7 1626
时光说笑
时光说笑 2020-12-01 03:34

When a view loads, i want to see if it\'s because the user pressed the back button. How can i check this?

7条回答
  •  無奈伤痛
    2020-12-01 04:07

    UINavigationController has a delegate property that issues delegate callbacks. Please see the iOS reference here.

    The delegate doesn't have a "back button pressed" callback, but instead it tells you when something is going to appear on the navigation stack. When you press back, you are "popping" the top view controller off the stack, so it will tell you that the view is about to appear. I think this is the callback you'd be looking for.

    You could have some simple logic to check if it's the view controller that's "interested", and then you could send a notification, et al.

提交回复
热议问题