Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3431434
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:19:32+00:00 2026-05-18T07:19:32+00:00

How to set action to the backButtonItem on the navigation bar? I have a

  • 0

How to set action to the backButtonItem on the navigation bar? I have a navigation bar, when I’m pressing the back button, I need to alert some message to the user, and only after user’s reaction – return to the previous view. How can I do it? Thanx!

- (void)viewDidLoad 
{
    [super viewDidLoad];

    //no one field don't changed yet
    isDirty = FALSE;

    //edited user
    //set default values
    newData = [data copy];

    //setting navigation controller rigth button
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Save"
                                                                style:UIBarButtonSystemItemDone 
                                                                   target: self 
                                                                   action: @selector(saveBtnUserClick)];
    self.navigationItem.rightBarButtonItem = rightButton; 
    [rightButton release];


    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
                                                                   style:UIBarButtonSystemItemDone 
                                                                  target: self 
                                                                  action: @selector(backBtnUserClick)];

    self.navigationItem.backBarButtonItem = leftButton;
    [leftButton release];
}

//and my method for reaction

-(IBAction) backBtnUserClick
{
    NSLog(@"\n Back pressed");

    //back to previous view
    [self.navigationController popViewControllerAnimated: TRUE];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:19:32+00:00Added an answer on May 18, 2026 at 7:19 am

    This sounds like a job for UIAlertView. Instead of calling popViewControllerAnimated: in your IBAction methods, alloc/init a UIAlertView and present it. Then, when the user taps a button on the UIAlertView, dismiss the UIAlertView and call popViewControllerAnimated:.

    - (IBAction)backBtnUserClicked:(id)object {
        UIAlertView *av = [[[UIAlertView alloc] initWithMessage:@"Wait!"
              delegate:self
                   cancelButtonTitle:@"Ok"
                   otherButtonTitles:nil] autorelease];
       [av show];
    }
    

    In your UIAlertViewDelegate methods call popViewControllerAnimated:.

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
        [[self navigationController] popViewControllerAnimated:YES];
    }
    

    To set the action on the back button:

    [[[self navigationController] leftBarButtonItem] setTarget:self];
    [[[self navigationController] leftBarButtonItem] setAction:@selector(backBtnUserClicked:)];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ico file that is embedded as a resource (build action set
I have a form action that needs to have its value set from a
How do I set an action for when a user double clicks an NSCollectionViewItem
Given a classic controller action. Have a look at the MARK. I need to
On a class library project, I set the Start Action on the Debug tab
I set up 404 handler page in web.config, but it works ONLY when extension
Im trying to set the action of a form with javascript! How come it
I have multiple business objects in my application (C#, Winforms, WinXP). When the user
UIControl makes a set of action messages available on controls that inherit from it.
setActionName: method description says that it set the action name for undo or redo

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.