I am an iOS development newbie. I am using the following code to set my backBarButtonItem -
UIBarButtonItem *temporaryBarButtonItem=[[UIBarButtonItem alloc] init];
temporaryBarButtonItem.title=@"Back";
self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
[temporaryBarButtonItem release];
I also want it to execute another function, apart from going back. Is that possible? Or do I need another button to save?
You can practically do that in your viewDidDisappear
or viewWillDisappear
method.
If this view can only go back and doesn't present any views, then this should work.
However, if you plan on presenting a subview, modal view, go deeper in the navigation hierarchy, or do other view operations that will cause viewDidDisapper
to get called, then you'll need to separate your back-button code logic somehow.
For instance if you will present a modal view from this view, you can check if self.modalViewController
is nil, if it is then you have no modal view being present and can safely execute the back-button code. If it is not nil then you have a modal view present and should not execute back-button code. (viewWillDisappear
should register the modal view controller as not-nil).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With