Remove only one RightBarButtonItem - ios

In navigation bar I'm adding two right barButtonItems:
[self.navigationItem setRightBarButtonItems:#[firstBarButton,secondBarButton]];
Now when I click over firstBarButtonItem want to remove it. I know when I have only one UIBarButtonItem I do:
self.navigationItem.rightBarButtonItem = nil;
How do I do when the rightBarButtonItems are two?

Just set one of them:
[self.navigationItem setRightBarButtonItem:secondBarButton];

Related

Is it possible to add a UIBarButtonItem besides a UISegmentedControl?

I've added a UISegmentedControl to a UINavigation Bar, and when I tried to add a UIBarButtonItem programmatically in viewDidLoad viewController using the following code:
UIBarButtonItem *timeTableBarButton = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:#"blueRoundRect"]
style:UIBarButtonItemStylePlain
target:self
action:#selector(popUpTimeTable)];
self.navigationItem.rightBarButtonItem = timeTableBarButton;
There are no button showing at all. I wonder since I already have a UISegmentedControl, is it possible to do so?
It is possible to add the Bar button in navigation bar and there is no way your segment control should be blocking right bar button item. Please make sure that your self.navigationItem is not nil.

Add goBack and goForward to the right of the Navigation Bar

I've a WebviewViewController and a navigation bar with the Back Bar Button. Now I want two buttons on the right of the bar, a goBack and a goForward. I've searching for a while and none of the answers works properly.
There's a way to add them in the storyboard or only programmatically? If so, how do I do it?
I did it in the past, it's easy:
myBackBarButton = [[UIBarButtonItem alloc] initWithImage:barButtonImage
style:UIBarButtonItemStylePlain
target:myWebView
action:#selector(goBack)];
myForwardButtom = [[UIBarButtonItem alloc] initWithImage:anotherBarButtonImage
style:UIBarButtonItemStylePlain
target:myWebView
action:#selector(goForward)];
Where myWebView is your UIWebView (In case it's your class, use self)
If your buttons are already created, then just add the target and the action to them:
myBackButton.target = myWebView;
myBackButton.action = #selector(goBack);
What you are doing is adding the action goForward: and goBack: of the target that is your webview, to those buttons.

Add a button next to the back button

in iOS, is it possible to add a button next to the default back button (the one that is automatically created when you use the method pushViewController)
I've tried to use the methods setLeftBarButtonItems and setBackBarButtonItem but in vain - whenever I set the left bar button items, the default back button disappears.
Thanks for your help!
Just do
self.navigationItem.leftItemsSupplementBackButton = YES;
self.navigationItem.leftBarButtonItems = #[item1, item2];
I haven't tested the following code, but it should work as long as the backBarButtonItem has been initialised.
[[self navigationItem] setLeftBarButtonItems:[NSArray arrayWithObjects:[[self navigationItem] backBarButtonItem], [[UIBarButtonItem alloc] initWithTitle:#"Custom" style:UIBarButtonItemStylePlain target:self action:#selector(action:)], nil]];\
Essentially, you're setting the entire left bar button item array from scratch but providing the back button along with your own custom button.

Is it possible to show a real Popover instead of default slide-out menu when using a UISplitViewController?

I am currently working with a UISplitViewController and instead of having this default slide-out-menu, i want a real UIPopover that appears if i click the UIBarButtonItem. What do i have to do and is there an easy way of configuring this ?
You first need to overwrite the left bar button item, with the button that can be used to display the popover.
Use the following -
UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithTitle:#"Popover" style:UIBarButtonItemStylePlain target:self action:#selector(presentPopover:)];
self.navigationItem.hidesBackButton = NO;
self.navigationItem.leftBarButtonItem = nil;
Now you can use the target added, and then perform the associated function, as per your choice.
-(IBAction)presentPopover:(id)sender
{
// Perform your operations
}
Then just use a popover view controller instead with the same content you would have used in the splitview pane that slides out.

Add another button next to the "back" button on the left of a UINavigationBar

I've tried this for hours but I still cannot solve it.
When using UINavigationController and push a new view controller on top, I got a free "back" button on the left of the navigation bar. I want another button just next to it (to show a popover menu). I wonder what is the correct way to do that. Or I have to hide the free back button and make the same one by myself? If that's the case, I also need to pop the current view controller when pressing my own back button, right?
Thanks for your help.
As stated by steipete in the comment to the question, this is possible starting from iOS 5. You can use
self.navigationItem.leftItemsSupplementBackButton = YES;
and then you just need to add an UIBarButtonItem as leftButton to get a second button after the back button
UIBarButtonItem *secondButton = [[UIBarButtonItem alloc] initWithTitle:#"Second" style:UIBarButtonItemStylePlain target:self action:#selector(yourAction)];
self.navigationItem.leftBarButtonItem = secondButton;
SWIFT 5 this worked for me. Thanks
self.navigationItem.leftItemsSupplementBackButton = true

Resources