Add a button next to the back button - ios

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.

Related

Remove only one RightBarButtonItem

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];

First UIBarButton disappears when second one is added

I am working on ios Bar Button icon where I have to display UIsegmented control with two UIBarButton icon on the right site but when I try to add second button using interface builder the first added button get disappears
This is how the view is added:
View->Navigation Bar->Navigation Item-> BarButton Item-> Button
Can anyone help me to find the possible solution
UIBarButtonItem *item1=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:#selector(firstSelector)];
UIBarButtonItem *item2=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(secondSelector)];
NSArray *items=[[NSArray alloc]initWithObjects:item1,item2, nil];
self.navigationItem.rightBarButtonItems=items;

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.

Xcode 4.5: I want to change a navigation bar button 'identifier' from play to pause

My story is the following. I've added a button to a tab bar, and I have set the button identifier to 'Play' so that it looks like a play button. I am using the identifier so that I don't have to use my own 'play.png' image.
When I press the button, apart from playing a sound, I want the image (identifier) to change to 'pause'. I'm unclear if one can, and if so how to make this change.
I've seen some examples of toggling buttons from play to pause etc. but they seem to be using local image files which I want to avoid.
Any help is appreciated.
Paul.
I had the same problem trying to change the button style with the default identifiers on runtime, I did a google research and I think it's impossible to do this so my solution was creating a new button and changing
it at runtime.
- (IBAction)playButton:(UIBarButtonItem *)sender {
if (self.scene.isPaused){
[self.scene setPaused:YES];
UIBarButtonItem *play = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:#selector(playButton:)];
play.style = UIBarButtonItemStyleBordered;
self.botToolbar.items = [NSArray arrayWithObject:play];
}
else{
[self.scene setPaused:NO];
UIBarButtonItem *pause = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPause target:self action:#selector(playButton:)];
pause.style = UIBarButtonItemStyleBordered;
self.botToolbar.items = [NSArray arrayWithObject:pause];
}
}
I use self.botToolbar.items cause I have a toolbar i added on the storyboard, if you want to use the toolbar of a NavigationController just change that for self.toolbarItems

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