I have an two controllers
1st is self
and 2nd is maincontroller
, where I'm pushing maincontroller
in stack, so the back button is automatically coming.
Here I need to make an alert when the user presses the back button.
How can I do this?
I have an two controllers
1st is self
and 2nd is maincontroller
, where I'm pushing maincontroller
in stack, so the back button is automatically coming.
Here I need to make an alert when the user presses the back button.
How can I do this?
First hide the back button by using
and then create your own Custom Button:
and your selector is here:
Or you can use the
UINavigationController
's delegate methods. The methodwillShowViewController
is called when the back button of your VC is pressed.Create your own
UIBarButtonItem
and set it as theleftBarButtonItem
inviewDidLoad
method ofmainController
.For example (here I used a system item but you can also create a different one, see class reference for details).
where
Best and Easiest way
Try putting this into the view controller where you want to detect the press:
viewControllerCount - is the var that holds the number of viewControllers previously was in the UINavigationController. Then, we check if viewControllerCount > [viewControllers count] if so, we know that we will get back (i.e. Back button imitation).
create a button and give the button action as follows.
and when the alert is displayed, after tapping over yes
after this,
this may help