how to disable a navigation bar button item in iOS












20














I have created a navigation controller. In the second view (which is pushed), I have some webservice call and placing a overlay view and setting



self.view.userInteractionEnabled = NO ;



Once web service call is complete, then I am reverting to



self.view.userInteractionEnabled = YES ;



When I do this, every other buttons except the buttons on the navigation bar are disabled. How to disable those two navigation bar button items ? (a button similar to back button, which pops to first view controller and another button which gives info about help).



I have tried using self.navigationItem.backBarButtonItem.enabled = NO. But still I am able to tap on the button and can navigate to first screen. How can I disable these two buttons ?










share|improve this question





























    20














    I have created a navigation controller. In the second view (which is pushed), I have some webservice call and placing a overlay view and setting



    self.view.userInteractionEnabled = NO ;



    Once web service call is complete, then I am reverting to



    self.view.userInteractionEnabled = YES ;



    When I do this, every other buttons except the buttons on the navigation bar are disabled. How to disable those two navigation bar button items ? (a button similar to back button, which pops to first view controller and another button which gives info about help).



    I have tried using self.navigationItem.backBarButtonItem.enabled = NO. But still I am able to tap on the button and can navigate to first screen. How can I disable these two buttons ?










    share|improve this question



























      20












      20








      20


      1





      I have created a navigation controller. In the second view (which is pushed), I have some webservice call and placing a overlay view and setting



      self.view.userInteractionEnabled = NO ;



      Once web service call is complete, then I am reverting to



      self.view.userInteractionEnabled = YES ;



      When I do this, every other buttons except the buttons on the navigation bar are disabled. How to disable those two navigation bar button items ? (a button similar to back button, which pops to first view controller and another button which gives info about help).



      I have tried using self.navigationItem.backBarButtonItem.enabled = NO. But still I am able to tap on the button and can navigate to first screen. How can I disable these two buttons ?










      share|improve this question















      I have created a navigation controller. In the second view (which is pushed), I have some webservice call and placing a overlay view and setting



      self.view.userInteractionEnabled = NO ;



      Once web service call is complete, then I am reverting to



      self.view.userInteractionEnabled = YES ;



      When I do this, every other buttons except the buttons on the navigation bar are disabled. How to disable those two navigation bar button items ? (a button similar to back button, which pops to first view controller and another button which gives info about help).



      I have tried using self.navigationItem.backBarButtonItem.enabled = NO. But still I am able to tap on the button and can navigate to first screen. How can I disable these two buttons ?







      ios ios7 uinavigationbar






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 18 '14 at 18:24









      rmaddy

      238k27310376




      238k27310376










      asked Aug 18 '14 at 11:18









      SravanSravan

      5123721




      5123721
























          12 Answers
          12






          active

          oldest

          votes


















          48














          Try this



          Recommended



          self.navigationItem.leftBarButtonItem.enabled = NO;

          self.navigationItem.rightBarButtonItem.enabled = NO;


          Or Simply Disable by



          on Edge case



          self.view.window.userInteractionEnabled = NO;


          Update:
          Recently Apple doesn't allow the back button to enable / disable. Instead of that we can hide it.



          self.navigationItem.hidesBackButton = YES;





          share|improve this answer



















          • 2




            Both didn't work. I am still able to tap the button and navigate to the first view controller.
            – Sravan
            Aug 18 '14 at 13:44










          • @Sravan Are you building the buttons in storyboard or dynamically? Building dynamically may have impact I suppose. Try placing this logic after you added the buttons to the navigationbar
            – Jay Mayu
            Mar 17 '15 at 6:03



















          12














          You can do the following if you are running on Swift



          self.navigationItem.rightBarButtonItem?.enabled = true


          This snippet will disable the button.






          share|improve this answer





























            8














            Just disable your UINavigationController view and navigation bar interaction:



            self.navigationController.navigationBar.userInteractionEnabled = NO;
            self.navigationController.view.userInteractionEnabled = NO;


            And enable it when you need it back:



            self.navigationController.navigationBar.userInteractionEnabled = YES;
            self.navigationController.view.userInteractionEnabled = YES;





            share|improve this answer



















            • 2




              This didnt worked. I am still able to tap the button and navigate to frist view controller.
              – Sravan
              Aug 18 '14 at 13:44










            • @Sravan I just edited my answer, does it work better?
              – jbouaziz
              Aug 18 '14 at 13:58










            • disabling interaction is fine and you can disable a button at a time, navigation bar buttons or the entire window. However, be sure you can always enable them. You might want to consider wrapping the 'disable' logic in a timer. For example, imagine you started a download but it did not finish correctly, is your app going to hang? Do you want to trigger a retry? Enable all?
              – goggelj
              Jul 12 '16 at 12:13





















            7














            Latest Swift: To hide the back button, you MUST use:



            self.navigationItem.setHidesBackButton(true, animated: false)


            Note: This can trigger a bug in the navigation bar that can cause an artifact to appear in place of a hidden back button when transitioning to a view that doesn't have a back button (or has a leftButton in its place). The artifact that appears is either ellipses "..." or the title of the previous viewController on the stack. I believe this bug to be related to the bug documented in apple's own sample code project "CustomizingUINavigationBar", CustomBackButtonViewController.m






            share|improve this answer































              2














              - (void)viewDidLoad
              {
              [super viewDidLoad];
              self.navigationItem.leftBarButtonItem=nil;
              self.navigationItem.hidesBackButton=YES;
              }





              share|improve this answer





























                1














                I solved this by just adding a property to my viewcontroller:



                @property (nonatomic, strong) IBOutlet UIBarButtonItem * RightButton;


                I then connected it to the button on the storyboard.
                You can then at will set its properties like:



                self.RightButton.enabled=true;





                share|improve this answer





























                  1















                  Updated for Swift 3:




                  If you want to disable a navigation bar button item OR you want to disable hole UINavigationBar i.e. all item present on navigation bar, use below lines of code;



                  // if you want disable
                  self.navigationController?.navigationBar.isUserInteractionEnabled = false

                  // if you want enable again
                  self.navigationController?.navigationBar.isUserInteractionEnabled = true


                  Enjoy...!






                  share|improve this answer





























                    1














                    For version iOS 10.3, swift 3:



                    self.navigationItem.rightBarButtonItem?.isEnabled = false.





                    share|improve this answer































                      0














                      One line solution



                      self.navigationController?.view.isUserInteractionEnabled = false





                      share|improve this answer





























                        0














                        Try this code:



                        UIApplication.sharedApplication().beginIgnoringInteractionEvents()


                        This will stop user to interaction with app and after service call, write this code again:



                        UIApplication.sharedApplication().endIgnoringInteractionEvents()


                        Sure this will help.






                        share|improve this answer































                          0














                          var menuBtn = new UIButton(UIButtonType.Custom);
                          menuBtn.Frame = new CGRect(x: 0.0, y: 0.0, width: 20, height: 20);
                          menuBtn.SetImage(new UIImage("filter"), UIControlState.Normal);

                          menuBtn.Alpha = 0.05f; //to set the Alpha

                          menuBtn.Enabled = false;


                          tested on Mvvmcross Xamarin.iOS only






                          share|improve this answer























                          • Add some description and format answer
                            – Billa
                            Aug 23 '18 at 11:15



















                          0














                          Navigation bar button items must be toggled by referring to them via the navigationItem property.



                          For example:



                          func setupNav() {
                          let saveButton = UIBarButtonItem.init(barButtonSystemItem: .save, target: self, action: #selector(onSavePressed))
                          navigationItem.rightBarButtonItem = saveButton
                          saveButton.isEnabled = false
                          }

                          func validateSave() {
                          saveButton.isEnabled = isConditionMet // WON'T work
                          navigationItem.rightBarButtonItem.isEnabled = isConditionMet // WORKS!
                          }





                          share|improve this answer





















                            Your Answer






                            StackExchange.ifUsing("editor", function () {
                            StackExchange.using("externalEditor", function () {
                            StackExchange.using("snippets", function () {
                            StackExchange.snippets.init();
                            });
                            });
                            }, "code-snippets");

                            StackExchange.ready(function() {
                            var channelOptions = {
                            tags: "".split(" "),
                            id: "1"
                            };
                            initTagRenderer("".split(" "), "".split(" "), channelOptions);

                            StackExchange.using("externalEditor", function() {
                            // Have to fire editor after snippets, if snippets enabled
                            if (StackExchange.settings.snippets.snippetsEnabled) {
                            StackExchange.using("snippets", function() {
                            createEditor();
                            });
                            }
                            else {
                            createEditor();
                            }
                            });

                            function createEditor() {
                            StackExchange.prepareEditor({
                            heartbeatType: 'answer',
                            autoActivateHeartbeat: false,
                            convertImagesToLinks: true,
                            noModals: true,
                            showLowRepImageUploadWarning: true,
                            reputationToPostImages: 10,
                            bindNavPrevention: true,
                            postfix: "",
                            imageUploader: {
                            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                            allowUrls: true
                            },
                            onDemand: true,
                            discardSelector: ".discard-answer"
                            ,immediatelyShowMarkdownHelp:true
                            });


                            }
                            });














                            draft saved

                            draft discarded


















                            StackExchange.ready(
                            function () {
                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25362050%2fhow-to-disable-a-navigation-bar-button-item-in-ios%23new-answer', 'question_page');
                            }
                            );

                            Post as a guest















                            Required, but never shown

























                            12 Answers
                            12






                            active

                            oldest

                            votes








                            12 Answers
                            12






                            active

                            oldest

                            votes









                            active

                            oldest

                            votes






                            active

                            oldest

                            votes









                            48














                            Try this



                            Recommended



                            self.navigationItem.leftBarButtonItem.enabled = NO;

                            self.navigationItem.rightBarButtonItem.enabled = NO;


                            Or Simply Disable by



                            on Edge case



                            self.view.window.userInteractionEnabled = NO;


                            Update:
                            Recently Apple doesn't allow the back button to enable / disable. Instead of that we can hide it.



                            self.navigationItem.hidesBackButton = YES;





                            share|improve this answer



















                            • 2




                              Both didn't work. I am still able to tap the button and navigate to the first view controller.
                              – Sravan
                              Aug 18 '14 at 13:44










                            • @Sravan Are you building the buttons in storyboard or dynamically? Building dynamically may have impact I suppose. Try placing this logic after you added the buttons to the navigationbar
                              – Jay Mayu
                              Mar 17 '15 at 6:03
















                            48














                            Try this



                            Recommended



                            self.navigationItem.leftBarButtonItem.enabled = NO;

                            self.navigationItem.rightBarButtonItem.enabled = NO;


                            Or Simply Disable by



                            on Edge case



                            self.view.window.userInteractionEnabled = NO;


                            Update:
                            Recently Apple doesn't allow the back button to enable / disable. Instead of that we can hide it.



                            self.navigationItem.hidesBackButton = YES;





                            share|improve this answer



















                            • 2




                              Both didn't work. I am still able to tap the button and navigate to the first view controller.
                              – Sravan
                              Aug 18 '14 at 13:44










                            • @Sravan Are you building the buttons in storyboard or dynamically? Building dynamically may have impact I suppose. Try placing this logic after you added the buttons to the navigationbar
                              – Jay Mayu
                              Mar 17 '15 at 6:03














                            48












                            48








                            48






                            Try this



                            Recommended



                            self.navigationItem.leftBarButtonItem.enabled = NO;

                            self.navigationItem.rightBarButtonItem.enabled = NO;


                            Or Simply Disable by



                            on Edge case



                            self.view.window.userInteractionEnabled = NO;


                            Update:
                            Recently Apple doesn't allow the back button to enable / disable. Instead of that we can hide it.



                            self.navigationItem.hidesBackButton = YES;





                            share|improve this answer














                            Try this



                            Recommended



                            self.navigationItem.leftBarButtonItem.enabled = NO;

                            self.navigationItem.rightBarButtonItem.enabled = NO;


                            Or Simply Disable by



                            on Edge case



                            self.view.window.userInteractionEnabled = NO;


                            Update:
                            Recently Apple doesn't allow the back button to enable / disable. Instead of that we can hide it.



                            self.navigationItem.hidesBackButton = YES;






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Dec 3 '14 at 9:01

























                            answered Aug 18 '14 at 11:33









                            Vijay-Apple-Dev.blogspot.comVijay-Apple-Dev.blogspot.com

                            24.4k76173




                            24.4k76173








                            • 2




                              Both didn't work. I am still able to tap the button and navigate to the first view controller.
                              – Sravan
                              Aug 18 '14 at 13:44










                            • @Sravan Are you building the buttons in storyboard or dynamically? Building dynamically may have impact I suppose. Try placing this logic after you added the buttons to the navigationbar
                              – Jay Mayu
                              Mar 17 '15 at 6:03














                            • 2




                              Both didn't work. I am still able to tap the button and navigate to the first view controller.
                              – Sravan
                              Aug 18 '14 at 13:44










                            • @Sravan Are you building the buttons in storyboard or dynamically? Building dynamically may have impact I suppose. Try placing this logic after you added the buttons to the navigationbar
                              – Jay Mayu
                              Mar 17 '15 at 6:03








                            2




                            2




                            Both didn't work. I am still able to tap the button and navigate to the first view controller.
                            – Sravan
                            Aug 18 '14 at 13:44




                            Both didn't work. I am still able to tap the button and navigate to the first view controller.
                            – Sravan
                            Aug 18 '14 at 13:44












                            @Sravan Are you building the buttons in storyboard or dynamically? Building dynamically may have impact I suppose. Try placing this logic after you added the buttons to the navigationbar
                            – Jay Mayu
                            Mar 17 '15 at 6:03




                            @Sravan Are you building the buttons in storyboard or dynamically? Building dynamically may have impact I suppose. Try placing this logic after you added the buttons to the navigationbar
                            – Jay Mayu
                            Mar 17 '15 at 6:03













                            12














                            You can do the following if you are running on Swift



                            self.navigationItem.rightBarButtonItem?.enabled = true


                            This snippet will disable the button.






                            share|improve this answer


























                              12














                              You can do the following if you are running on Swift



                              self.navigationItem.rightBarButtonItem?.enabled = true


                              This snippet will disable the button.






                              share|improve this answer
























                                12












                                12








                                12






                                You can do the following if you are running on Swift



                                self.navigationItem.rightBarButtonItem?.enabled = true


                                This snippet will disable the button.






                                share|improve this answer












                                You can do the following if you are running on Swift



                                self.navigationItem.rightBarButtonItem?.enabled = true


                                This snippet will disable the button.







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Jul 8 '15 at 9:30









                                Jay MayuJay Mayu

                                10.7k28100135




                                10.7k28100135























                                    8














                                    Just disable your UINavigationController view and navigation bar interaction:



                                    self.navigationController.navigationBar.userInteractionEnabled = NO;
                                    self.navigationController.view.userInteractionEnabled = NO;


                                    And enable it when you need it back:



                                    self.navigationController.navigationBar.userInteractionEnabled = YES;
                                    self.navigationController.view.userInteractionEnabled = YES;





                                    share|improve this answer



















                                    • 2




                                      This didnt worked. I am still able to tap the button and navigate to frist view controller.
                                      – Sravan
                                      Aug 18 '14 at 13:44










                                    • @Sravan I just edited my answer, does it work better?
                                      – jbouaziz
                                      Aug 18 '14 at 13:58










                                    • disabling interaction is fine and you can disable a button at a time, navigation bar buttons or the entire window. However, be sure you can always enable them. You might want to consider wrapping the 'disable' logic in a timer. For example, imagine you started a download but it did not finish correctly, is your app going to hang? Do you want to trigger a retry? Enable all?
                                      – goggelj
                                      Jul 12 '16 at 12:13


















                                    8














                                    Just disable your UINavigationController view and navigation bar interaction:



                                    self.navigationController.navigationBar.userInteractionEnabled = NO;
                                    self.navigationController.view.userInteractionEnabled = NO;


                                    And enable it when you need it back:



                                    self.navigationController.navigationBar.userInteractionEnabled = YES;
                                    self.navigationController.view.userInteractionEnabled = YES;





                                    share|improve this answer



















                                    • 2




                                      This didnt worked. I am still able to tap the button and navigate to frist view controller.
                                      – Sravan
                                      Aug 18 '14 at 13:44










                                    • @Sravan I just edited my answer, does it work better?
                                      – jbouaziz
                                      Aug 18 '14 at 13:58










                                    • disabling interaction is fine and you can disable a button at a time, navigation bar buttons or the entire window. However, be sure you can always enable them. You might want to consider wrapping the 'disable' logic in a timer. For example, imagine you started a download but it did not finish correctly, is your app going to hang? Do you want to trigger a retry? Enable all?
                                      – goggelj
                                      Jul 12 '16 at 12:13
















                                    8












                                    8








                                    8






                                    Just disable your UINavigationController view and navigation bar interaction:



                                    self.navigationController.navigationBar.userInteractionEnabled = NO;
                                    self.navigationController.view.userInteractionEnabled = NO;


                                    And enable it when you need it back:



                                    self.navigationController.navigationBar.userInteractionEnabled = YES;
                                    self.navigationController.view.userInteractionEnabled = YES;





                                    share|improve this answer














                                    Just disable your UINavigationController view and navigation bar interaction:



                                    self.navigationController.navigationBar.userInteractionEnabled = NO;
                                    self.navigationController.view.userInteractionEnabled = NO;


                                    And enable it when you need it back:



                                    self.navigationController.navigationBar.userInteractionEnabled = YES;
                                    self.navigationController.view.userInteractionEnabled = YES;






                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Aug 18 '14 at 13:58

























                                    answered Aug 18 '14 at 11:44









                                    jbouazizjbouaziz

                                    1,39011022




                                    1,39011022








                                    • 2




                                      This didnt worked. I am still able to tap the button and navigate to frist view controller.
                                      – Sravan
                                      Aug 18 '14 at 13:44










                                    • @Sravan I just edited my answer, does it work better?
                                      – jbouaziz
                                      Aug 18 '14 at 13:58










                                    • disabling interaction is fine and you can disable a button at a time, navigation bar buttons or the entire window. However, be sure you can always enable them. You might want to consider wrapping the 'disable' logic in a timer. For example, imagine you started a download but it did not finish correctly, is your app going to hang? Do you want to trigger a retry? Enable all?
                                      – goggelj
                                      Jul 12 '16 at 12:13
















                                    • 2




                                      This didnt worked. I am still able to tap the button and navigate to frist view controller.
                                      – Sravan
                                      Aug 18 '14 at 13:44










                                    • @Sravan I just edited my answer, does it work better?
                                      – jbouaziz
                                      Aug 18 '14 at 13:58










                                    • disabling interaction is fine and you can disable a button at a time, navigation bar buttons or the entire window. However, be sure you can always enable them. You might want to consider wrapping the 'disable' logic in a timer. For example, imagine you started a download but it did not finish correctly, is your app going to hang? Do you want to trigger a retry? Enable all?
                                      – goggelj
                                      Jul 12 '16 at 12:13










                                    2




                                    2




                                    This didnt worked. I am still able to tap the button and navigate to frist view controller.
                                    – Sravan
                                    Aug 18 '14 at 13:44




                                    This didnt worked. I am still able to tap the button and navigate to frist view controller.
                                    – Sravan
                                    Aug 18 '14 at 13:44












                                    @Sravan I just edited my answer, does it work better?
                                    – jbouaziz
                                    Aug 18 '14 at 13:58




                                    @Sravan I just edited my answer, does it work better?
                                    – jbouaziz
                                    Aug 18 '14 at 13:58












                                    disabling interaction is fine and you can disable a button at a time, navigation bar buttons or the entire window. However, be sure you can always enable them. You might want to consider wrapping the 'disable' logic in a timer. For example, imagine you started a download but it did not finish correctly, is your app going to hang? Do you want to trigger a retry? Enable all?
                                    – goggelj
                                    Jul 12 '16 at 12:13






                                    disabling interaction is fine and you can disable a button at a time, navigation bar buttons or the entire window. However, be sure you can always enable them. You might want to consider wrapping the 'disable' logic in a timer. For example, imagine you started a download but it did not finish correctly, is your app going to hang? Do you want to trigger a retry? Enable all?
                                    – goggelj
                                    Jul 12 '16 at 12:13













                                    7














                                    Latest Swift: To hide the back button, you MUST use:



                                    self.navigationItem.setHidesBackButton(true, animated: false)


                                    Note: This can trigger a bug in the navigation bar that can cause an artifact to appear in place of a hidden back button when transitioning to a view that doesn't have a back button (or has a leftButton in its place). The artifact that appears is either ellipses "..." or the title of the previous viewController on the stack. I believe this bug to be related to the bug documented in apple's own sample code project "CustomizingUINavigationBar", CustomBackButtonViewController.m






                                    share|improve this answer




























                                      7














                                      Latest Swift: To hide the back button, you MUST use:



                                      self.navigationItem.setHidesBackButton(true, animated: false)


                                      Note: This can trigger a bug in the navigation bar that can cause an artifact to appear in place of a hidden back button when transitioning to a view that doesn't have a back button (or has a leftButton in its place). The artifact that appears is either ellipses "..." or the title of the previous viewController on the stack. I believe this bug to be related to the bug documented in apple's own sample code project "CustomizingUINavigationBar", CustomBackButtonViewController.m






                                      share|improve this answer


























                                        7












                                        7








                                        7






                                        Latest Swift: To hide the back button, you MUST use:



                                        self.navigationItem.setHidesBackButton(true, animated: false)


                                        Note: This can trigger a bug in the navigation bar that can cause an artifact to appear in place of a hidden back button when transitioning to a view that doesn't have a back button (or has a leftButton in its place). The artifact that appears is either ellipses "..." or the title of the previous viewController on the stack. I believe this bug to be related to the bug documented in apple's own sample code project "CustomizingUINavigationBar", CustomBackButtonViewController.m






                                        share|improve this answer














                                        Latest Swift: To hide the back button, you MUST use:



                                        self.navigationItem.setHidesBackButton(true, animated: false)


                                        Note: This can trigger a bug in the navigation bar that can cause an artifact to appear in place of a hidden back button when transitioning to a view that doesn't have a back button (or has a leftButton in its place). The artifact that appears is either ellipses "..." or the title of the previous viewController on the stack. I believe this bug to be related to the bug documented in apple's own sample code project "CustomizingUINavigationBar", CustomBackButtonViewController.m







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Sep 10 '15 at 14:19

























                                        answered Sep 10 '15 at 14:08









                                        ObjectiveTCObjectiveTC

                                        1,5932218




                                        1,5932218























                                            2














                                            - (void)viewDidLoad
                                            {
                                            [super viewDidLoad];
                                            self.navigationItem.leftBarButtonItem=nil;
                                            self.navigationItem.hidesBackButton=YES;
                                            }





                                            share|improve this answer


























                                              2














                                              - (void)viewDidLoad
                                              {
                                              [super viewDidLoad];
                                              self.navigationItem.leftBarButtonItem=nil;
                                              self.navigationItem.hidesBackButton=YES;
                                              }





                                              share|improve this answer
























                                                2












                                                2








                                                2






                                                - (void)viewDidLoad
                                                {
                                                [super viewDidLoad];
                                                self.navigationItem.leftBarButtonItem=nil;
                                                self.navigationItem.hidesBackButton=YES;
                                                }





                                                share|improve this answer












                                                - (void)viewDidLoad
                                                {
                                                [super viewDidLoad];
                                                self.navigationItem.leftBarButtonItem=nil;
                                                self.navigationItem.hidesBackButton=YES;
                                                }






                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Oct 15 '15 at 5:41







                                                user4919266






























                                                    1














                                                    I solved this by just adding a property to my viewcontroller:



                                                    @property (nonatomic, strong) IBOutlet UIBarButtonItem * RightButton;


                                                    I then connected it to the button on the storyboard.
                                                    You can then at will set its properties like:



                                                    self.RightButton.enabled=true;





                                                    share|improve this answer


























                                                      1














                                                      I solved this by just adding a property to my viewcontroller:



                                                      @property (nonatomic, strong) IBOutlet UIBarButtonItem * RightButton;


                                                      I then connected it to the button on the storyboard.
                                                      You can then at will set its properties like:



                                                      self.RightButton.enabled=true;





                                                      share|improve this answer
























                                                        1












                                                        1








                                                        1






                                                        I solved this by just adding a property to my viewcontroller:



                                                        @property (nonatomic, strong) IBOutlet UIBarButtonItem * RightButton;


                                                        I then connected it to the button on the storyboard.
                                                        You can then at will set its properties like:



                                                        self.RightButton.enabled=true;





                                                        share|improve this answer












                                                        I solved this by just adding a property to my viewcontroller:



                                                        @property (nonatomic, strong) IBOutlet UIBarButtonItem * RightButton;


                                                        I then connected it to the button on the storyboard.
                                                        You can then at will set its properties like:



                                                        self.RightButton.enabled=true;






                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Feb 13 '17 at 11:15









                                                        SjakelienSjakelien

                                                        87521130




                                                        87521130























                                                            1















                                                            Updated for Swift 3:




                                                            If you want to disable a navigation bar button item OR you want to disable hole UINavigationBar i.e. all item present on navigation bar, use below lines of code;



                                                            // if you want disable
                                                            self.navigationController?.navigationBar.isUserInteractionEnabled = false

                                                            // if you want enable again
                                                            self.navigationController?.navigationBar.isUserInteractionEnabled = true


                                                            Enjoy...!






                                                            share|improve this answer


























                                                              1















                                                              Updated for Swift 3:




                                                              If you want to disable a navigation bar button item OR you want to disable hole UINavigationBar i.e. all item present on navigation bar, use below lines of code;



                                                              // if you want disable
                                                              self.navigationController?.navigationBar.isUserInteractionEnabled = false

                                                              // if you want enable again
                                                              self.navigationController?.navigationBar.isUserInteractionEnabled = true


                                                              Enjoy...!






                                                              share|improve this answer
























                                                                1












                                                                1








                                                                1







                                                                Updated for Swift 3:




                                                                If you want to disable a navigation bar button item OR you want to disable hole UINavigationBar i.e. all item present on navigation bar, use below lines of code;



                                                                // if you want disable
                                                                self.navigationController?.navigationBar.isUserInteractionEnabled = false

                                                                // if you want enable again
                                                                self.navigationController?.navigationBar.isUserInteractionEnabled = true


                                                                Enjoy...!






                                                                share|improve this answer













                                                                Updated for Swift 3:




                                                                If you want to disable a navigation bar button item OR you want to disable hole UINavigationBar i.e. all item present on navigation bar, use below lines of code;



                                                                // if you want disable
                                                                self.navigationController?.navigationBar.isUserInteractionEnabled = false

                                                                // if you want enable again
                                                                self.navigationController?.navigationBar.isUserInteractionEnabled = true


                                                                Enjoy...!







                                                                share|improve this answer












                                                                share|improve this answer



                                                                share|improve this answer










                                                                answered Dec 8 '17 at 4:38









                                                                Kiran jadhavKiran jadhav

                                                                1,5451417




                                                                1,5451417























                                                                    1














                                                                    For version iOS 10.3, swift 3:



                                                                    self.navigationItem.rightBarButtonItem?.isEnabled = false.





                                                                    share|improve this answer




























                                                                      1














                                                                      For version iOS 10.3, swift 3:



                                                                      self.navigationItem.rightBarButtonItem?.isEnabled = false.





                                                                      share|improve this answer


























                                                                        1












                                                                        1








                                                                        1






                                                                        For version iOS 10.3, swift 3:



                                                                        self.navigationItem.rightBarButtonItem?.isEnabled = false.





                                                                        share|improve this answer














                                                                        For version iOS 10.3, swift 3:



                                                                        self.navigationItem.rightBarButtonItem?.isEnabled = false.






                                                                        share|improve this answer














                                                                        share|improve this answer



                                                                        share|improve this answer








                                                                        edited Nov 23 '18 at 7:46









                                                                        kit

                                                                        1,1063716




                                                                        1,1063716










                                                                        answered Mar 7 '18 at 9:48









                                                                        Sagar DSagar D

                                                                        1056




                                                                        1056























                                                                            0














                                                                            One line solution



                                                                            self.navigationController?.view.isUserInteractionEnabled = false





                                                                            share|improve this answer


























                                                                              0














                                                                              One line solution



                                                                              self.navigationController?.view.isUserInteractionEnabled = false





                                                                              share|improve this answer
























                                                                                0












                                                                                0








                                                                                0






                                                                                One line solution



                                                                                self.navigationController?.view.isUserInteractionEnabled = false





                                                                                share|improve this answer












                                                                                One line solution



                                                                                self.navigationController?.view.isUserInteractionEnabled = false






                                                                                share|improve this answer












                                                                                share|improve this answer



                                                                                share|improve this answer










                                                                                answered Oct 11 '17 at 12:05









                                                                                Ghulam RasoolGhulam Rasool

                                                                                2,12911326




                                                                                2,12911326























                                                                                    0














                                                                                    Try this code:



                                                                                    UIApplication.sharedApplication().beginIgnoringInteractionEvents()


                                                                                    This will stop user to interaction with app and after service call, write this code again:



                                                                                    UIApplication.sharedApplication().endIgnoringInteractionEvents()


                                                                                    Sure this will help.






                                                                                    share|improve this answer




























                                                                                      0














                                                                                      Try this code:



                                                                                      UIApplication.sharedApplication().beginIgnoringInteractionEvents()


                                                                                      This will stop user to interaction with app and after service call, write this code again:



                                                                                      UIApplication.sharedApplication().endIgnoringInteractionEvents()


                                                                                      Sure this will help.






                                                                                      share|improve this answer


























                                                                                        0












                                                                                        0








                                                                                        0






                                                                                        Try this code:



                                                                                        UIApplication.sharedApplication().beginIgnoringInteractionEvents()


                                                                                        This will stop user to interaction with app and after service call, write this code again:



                                                                                        UIApplication.sharedApplication().endIgnoringInteractionEvents()


                                                                                        Sure this will help.






                                                                                        share|improve this answer














                                                                                        Try this code:



                                                                                        UIApplication.sharedApplication().beginIgnoringInteractionEvents()


                                                                                        This will stop user to interaction with app and after service call, write this code again:



                                                                                        UIApplication.sharedApplication().endIgnoringInteractionEvents()


                                                                                        Sure this will help.







                                                                                        share|improve this answer














                                                                                        share|improve this answer



                                                                                        share|improve this answer








                                                                                        edited Nov 23 '18 at 10:59









                                                                                        kit

                                                                                        1,1063716




                                                                                        1,1063716










                                                                                        answered Jun 29 '16 at 9:15









                                                                                        Muhammad FasiMuhammad Fasi

                                                                                        577




                                                                                        577























                                                                                            0














                                                                                            var menuBtn = new UIButton(UIButtonType.Custom);
                                                                                            menuBtn.Frame = new CGRect(x: 0.0, y: 0.0, width: 20, height: 20);
                                                                                            menuBtn.SetImage(new UIImage("filter"), UIControlState.Normal);

                                                                                            menuBtn.Alpha = 0.05f; //to set the Alpha

                                                                                            menuBtn.Enabled = false;


                                                                                            tested on Mvvmcross Xamarin.iOS only






                                                                                            share|improve this answer























                                                                                            • Add some description and format answer
                                                                                              – Billa
                                                                                              Aug 23 '18 at 11:15
















                                                                                            0














                                                                                            var menuBtn = new UIButton(UIButtonType.Custom);
                                                                                            menuBtn.Frame = new CGRect(x: 0.0, y: 0.0, width: 20, height: 20);
                                                                                            menuBtn.SetImage(new UIImage("filter"), UIControlState.Normal);

                                                                                            menuBtn.Alpha = 0.05f; //to set the Alpha

                                                                                            menuBtn.Enabled = false;


                                                                                            tested on Mvvmcross Xamarin.iOS only






                                                                                            share|improve this answer























                                                                                            • Add some description and format answer
                                                                                              – Billa
                                                                                              Aug 23 '18 at 11:15














                                                                                            0












                                                                                            0








                                                                                            0






                                                                                            var menuBtn = new UIButton(UIButtonType.Custom);
                                                                                            menuBtn.Frame = new CGRect(x: 0.0, y: 0.0, width: 20, height: 20);
                                                                                            menuBtn.SetImage(new UIImage("filter"), UIControlState.Normal);

                                                                                            menuBtn.Alpha = 0.05f; //to set the Alpha

                                                                                            menuBtn.Enabled = false;


                                                                                            tested on Mvvmcross Xamarin.iOS only






                                                                                            share|improve this answer














                                                                                            var menuBtn = new UIButton(UIButtonType.Custom);
                                                                                            menuBtn.Frame = new CGRect(x: 0.0, y: 0.0, width: 20, height: 20);
                                                                                            menuBtn.SetImage(new UIImage("filter"), UIControlState.Normal);

                                                                                            menuBtn.Alpha = 0.05f; //to set the Alpha

                                                                                            menuBtn.Enabled = false;


                                                                                            tested on Mvvmcross Xamarin.iOS only







                                                                                            share|improve this answer














                                                                                            share|improve this answer



                                                                                            share|improve this answer








                                                                                            edited Nov 23 '18 at 11:12









                                                                                            ttarchala

                                                                                            2,0791929




                                                                                            2,0791929










                                                                                            answered Aug 23 '18 at 10:57









                                                                                            KomiconKomicon

                                                                                            105




                                                                                            105












                                                                                            • Add some description and format answer
                                                                                              – Billa
                                                                                              Aug 23 '18 at 11:15


















                                                                                            • Add some description and format answer
                                                                                              – Billa
                                                                                              Aug 23 '18 at 11:15
















                                                                                            Add some description and format answer
                                                                                            – Billa
                                                                                            Aug 23 '18 at 11:15




                                                                                            Add some description and format answer
                                                                                            – Billa
                                                                                            Aug 23 '18 at 11:15











                                                                                            0














                                                                                            Navigation bar button items must be toggled by referring to them via the navigationItem property.



                                                                                            For example:



                                                                                            func setupNav() {
                                                                                            let saveButton = UIBarButtonItem.init(barButtonSystemItem: .save, target: self, action: #selector(onSavePressed))
                                                                                            navigationItem.rightBarButtonItem = saveButton
                                                                                            saveButton.isEnabled = false
                                                                                            }

                                                                                            func validateSave() {
                                                                                            saveButton.isEnabled = isConditionMet // WON'T work
                                                                                            navigationItem.rightBarButtonItem.isEnabled = isConditionMet // WORKS!
                                                                                            }





                                                                                            share|improve this answer


























                                                                                              0














                                                                                              Navigation bar button items must be toggled by referring to them via the navigationItem property.



                                                                                              For example:



                                                                                              func setupNav() {
                                                                                              let saveButton = UIBarButtonItem.init(barButtonSystemItem: .save, target: self, action: #selector(onSavePressed))
                                                                                              navigationItem.rightBarButtonItem = saveButton
                                                                                              saveButton.isEnabled = false
                                                                                              }

                                                                                              func validateSave() {
                                                                                              saveButton.isEnabled = isConditionMet // WON'T work
                                                                                              navigationItem.rightBarButtonItem.isEnabled = isConditionMet // WORKS!
                                                                                              }





                                                                                              share|improve this answer
























                                                                                                0












                                                                                                0








                                                                                                0






                                                                                                Navigation bar button items must be toggled by referring to them via the navigationItem property.



                                                                                                For example:



                                                                                                func setupNav() {
                                                                                                let saveButton = UIBarButtonItem.init(barButtonSystemItem: .save, target: self, action: #selector(onSavePressed))
                                                                                                navigationItem.rightBarButtonItem = saveButton
                                                                                                saveButton.isEnabled = false
                                                                                                }

                                                                                                func validateSave() {
                                                                                                saveButton.isEnabled = isConditionMet // WON'T work
                                                                                                navigationItem.rightBarButtonItem.isEnabled = isConditionMet // WORKS!
                                                                                                }





                                                                                                share|improve this answer












                                                                                                Navigation bar button items must be toggled by referring to them via the navigationItem property.



                                                                                                For example:



                                                                                                func setupNav() {
                                                                                                let saveButton = UIBarButtonItem.init(barButtonSystemItem: .save, target: self, action: #selector(onSavePressed))
                                                                                                navigationItem.rightBarButtonItem = saveButton
                                                                                                saveButton.isEnabled = false
                                                                                                }

                                                                                                func validateSave() {
                                                                                                saveButton.isEnabled = isConditionMet // WON'T work
                                                                                                navigationItem.rightBarButtonItem.isEnabled = isConditionMet // WORKS!
                                                                                                }






                                                                                                share|improve this answer












                                                                                                share|improve this answer



                                                                                                share|improve this answer










                                                                                                answered Dec 18 '18 at 5:49









                                                                                                DiviyoDiviyo

                                                                                                1




                                                                                                1






























                                                                                                    draft saved

                                                                                                    draft discarded




















































                                                                                                    Thanks for contributing an answer to Stack Overflow!


                                                                                                    • Please be sure to answer the question. Provide details and share your research!

                                                                                                    But avoid



                                                                                                    • Asking for help, clarification, or responding to other answers.

                                                                                                    • Making statements based on opinion; back them up with references or personal experience.


                                                                                                    To learn more, see our tips on writing great answers.





                                                                                                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                                                                    Please pay close attention to the following guidance:


                                                                                                    • Please be sure to answer the question. Provide details and share your research!

                                                                                                    But avoid



                                                                                                    • Asking for help, clarification, or responding to other answers.

                                                                                                    • Making statements based on opinion; back them up with references or personal experience.


                                                                                                    To learn more, see our tips on writing great answers.




                                                                                                    draft saved


                                                                                                    draft discarded














                                                                                                    StackExchange.ready(
                                                                                                    function () {
                                                                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25362050%2fhow-to-disable-a-navigation-bar-button-item-in-ios%23new-answer', 'question_page');
                                                                                                    }
                                                                                                    );

                                                                                                    Post as a guest















                                                                                                    Required, but never shown





















































                                                                                                    Required, but never shown














                                                                                                    Required, but never shown












                                                                                                    Required, but never shown







                                                                                                    Required, but never shown

































                                                                                                    Required, but never shown














                                                                                                    Required, but never shown












                                                                                                    Required, but never shown







                                                                                                    Required, but never shown







                                                                                                    Popular posts from this blog

                                                                                                    What visual should I use to simply compare current year value vs last year in Power BI desktop

                                                                                                    Alexandru Averescu

                                                                                                    Trompette piccolo