how to disable a navigation bar button item in iOS

前端 未结 16 1264
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-01 09:54

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.use

相关标签:
16条回答
  • 2021-01-01 10:02

    You can do the following if you are running on Swift

    self.navigationItem.rightBarButtonItem?.enabled = true
    

    This snippet will disable the button.

    0 讨论(0)
  • 2021-01-01 10:02

    Swift 5 & iOS 13 :

    To remove all left buttons or just a specified one just remove from leftBarButtonItems Array.

            self.navigationItem.leftBarButtonItems = []
    
    0 讨论(0)
  • 2021-01-01 10:05
    - (void)viewDidLoad
    {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem=nil;
    self.navigationItem.hidesBackButton=YES;
    }
    
    0 讨论(0)
  • 2021-01-01 10:06

    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;
    
    0 讨论(0)
  • 2021-01-01 10:07

    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.

    0 讨论(0)
  • 2021-01-01 10:08

    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

    0 讨论(0)
提交回复
热议问题