logo
down
shadow

Execute action when back bar button of UINavigationController is pressed


Execute action when back bar button of UINavigationController is pressed

By : Jerin
Date : November 22 2020, 10:38 AM
I wish did fix the issue. One option would be implementing your own custom back button. You would need to add the following code to your viewDidLoad method:
code :
- (void) viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.hidesBackButton = YES;
    UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(back:)];
    self.navigationItem.leftBarButtonItem = newBackButton;
}

- (void) back:(UIBarButtonItem *)sender {
    // Perform your custom actions
    // ...
    // Go back to the previous ViewController
    [self.navigationController popViewControllerAnimated:YES];
}
    override func viewDidLoad {
        super.viewDidLoad()
        self.navigationItem.hidesBackButton = true
        let newBackButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Bordered, target: self, action: "back:")
        self.navigationItem.leftBarButtonItem = newBackButton
    }

    func back(sender: UIBarButtonItem) {
        // Perform your custom actions
        // ...
        // Go back to the previous ViewController
        self.navigationController?.popViewControllerAnimated(true)
    }
    override func viewDidLoad {
        super.viewDidLoad()
        self.navigationItem.hidesBackButton = true
        let newBackButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.plain, target: self, action: #selector(YourViewController.back(sender:)))
        self.navigationItem.leftBarButtonItem = newBackButton
    }

    func back(sender: UIBarButtonItem) {
        // Perform your custom actions
        // ...
        // Go back to the previous ViewController
        _ = navigationController?.popViewController(animated: true)
    }


Share : facebook icon twitter icon
iPhone Dev, UINavigationController, How to Programmatically Tell when Back Button is Pressed

iPhone Dev, UINavigationController, How to Programmatically Tell when Back Button is Pressed


By : David Fabian Paz Vie
Date : March 29 2020, 07:55 AM
I wish this helpful for you When you press the button programmatically set a flag. When you go to perform the post press actions check if the flag is set.
Find out if user pressed the back button in uinavigationcontroller?

Find out if user pressed the back button in uinavigationcontroller?


By : user3101067
Date : March 29 2020, 07:55 AM
it fixes the issue The only way to do this so you know for sure that it was the back button is to create a custom button. If you don't know how to do that, check out this tutorial. It won't look exactly like the normal back button, but close. If you need more help, post a comment
How to call viewDidLoad method when back button is pressed in UINavigationController? (iPhone / iPad)

How to call viewDidLoad method when back button is pressed in UINavigationController? (iPhone / iPad)


By : Panos Vasilikos
Date : March 29 2020, 07:55 AM
it fixes the issue The viewDidLoad method is called when the view controller has finished loading and setting up the view controller, for example loading the NIB file. For your needs, you should move the relevant code to viewWillAppear which will be called each time the corresponding view controller becomes visible. So for a transition A -> B -> C (backto)-> B the viewWillAppear method of B's view controller will be called twice.
How to call a method when back button on a UINavigationController is pressed? (iPhone)

How to call a method when back button on a UINavigationController is pressed? (iPhone)


By : Bethuel
Date : March 29 2020, 07:55 AM
seems to work fine A fast solution is to add an implementation for the viewWillDisappear: method. It will be triggered as soon as the viewController will disappear in response to the back button pression.
code :
- (void)viewWillDisappear:(BOOL)animated {
  //... 
  //make you stuff here
  //... 
}
- (id)init {
    if (self = [super init]) {
        //other your stuff goes here
        //... 
        //here we customize the target and action for the backBarButtonItem
        //every navigationController has one of this item automatically configured to pop back
        self.navigationItem.backBarButtonItem.target = self;
        self.navigationItem.backBarButtonItem.action = @selector(backButtonDidPressed:);
    }
    return self;
}
- (void)backButtonDidPressed:(id)aResponder {
    //do your stuff
    //but don't forget to dismiss the viewcontroller
    [self.navigationController popViewControllerAnimated:TRUE];
}
UINavigationController and back button action

UINavigationController and back button action


By : Raksha Pai
Date : March 29 2020, 07:55 AM
To fix this issue Or you can use the UINavigationController's delegate methods. The method willShowViewController is called when the back button of your VC is pressed.
code :
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
Related Posts Related Posts :
  • Programmatically set size of UIView from Storyboard
  • Navigation bar blink
  • Web services issue on POST method
  • Parse.com error 'Method not allowed when Pinning is enabled.' when I use a PFQueryTableViewController subclass
  • Swift can't send URLRequest at all?
  • No Provisiong profiles with a valid signing identity were found and Failed to locate or generate matching signing assets
  • iOS: how to set httponly flag for NSHTTPCookie
  • How to get the mac address of a beacon in objective-c without knowing its UUID, major and minor values?
  • tableView is not showing data from JSON in swift
  • iTunes reject app for date of birth
  • SWIFT reporting "Extra argument in call" - works in Playground
  • save data depending on passed value in swift
  • webview not showing on full Screen of iphone 6
  • Location Notification's based on Latest iOS Feature
  • Adjusting Height of UITableViewCell
  • How to show five digit unicode in iphone
  • unwind doesn't work
  • Confusion about coordinates, frames & child nodes in SpriteKit on iOS?
  • If Statements not being recognized by Xcode
  • readonly property in RubyMotion
  • 'No available types for source 1' when the app runs on my device(IPhone 6) swift
  • IOS:Remove view when clicked in background
  • Removing "\" from URL in iOS Swift
  • iOS - Send an email automatically (NOT from user's account)
  • The usage of NSNotificationCenter in the relationship of parent and children
  • When do Apple auto-renewable subscriptions renew?
  • Unknown large spacing between x-axis label and base of plot in core-plot
  • How do I change the displayed time format after NSTimer is initiated?
  • Swift JSON breaks when [ ] are used
  • Secure Memory For Swift Objects
  • didSelectItemAtIndexPath doesn't work normally
  • Swift Documentation Comments
  • Is there a simple way to assign a value only once(first time) inside a loop/repeatedly running method?
  • Play sound in while app in background
  • If I have an embedded unrestricted webview, does that mean I have third-party content?
  • UITapGestureRecognizer on UIScrollView
  • App does not respond to hardware volume changes on iPad
  • troubleshoot asp.net web app on iOS
  • What size should my tab bar item icons be?
  • Parse.com Facebook authorize never calls completion handler
  • Implementing iAds on a SceneKit view
  • UIAccessibility and Apple Pay voice-over interaction issue
  • Getting objectForKeyedSubscript unrecognized selector when parsing data in table view
  • iOS Table View - Set tag on cell or label?
  • Preferred approach for changing UITableViewCell content based on cell width
  • NSDateformatter dateFromString AnyObject
  • Type specifier for NSMutableArray?
  • iOS7 slideout drawer draggable bug
  • Fetch Core Data entity with a filtered set of child elements based on a property
  • UILabel AutoResize Swift
  • Swift - Selecting cells when having multiple custom cell-classes
  • Table View Cell Prototype from Storyboard not initializing subviews
  • Best way to implement view like map
  • Adding a tap gesture to a UIImageView to change a UILabel?
  • Minimum OS X and xcode requirements for ios 8.1 development
  • Changing the text of the Cancel button in the default TouchID dialog
  • iOS timing between taps
  • Swift: How do I link an action to a view inside of a tableViewCell?
  • Value for frame.size.height is always the same regardless of height of view
  • WatchKit / Apple Watch API: vibrations of custom length?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org