UIBarButtonItem disappears - ios

Why would my UIBarButtonItem sometimes disappear?
When you first load the screen (the first in a Tab Bar) it displays fine. However when you navigate to a new screen and then return both left and right buttons disappear. They aren't reacting to touch events either. However, if you go to a second tab and return they suddenly appear.
It must be a recent iOS change 'cos it was working previously.
==== UPDATE
The code is hardly rocket science but here it is:
Screen 1:
In viewDidLoad:
UIImage *myImage = [UIImage imageNamed:#"image.png"];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:myImage
style:UIBarButtonItemStyleBordered
target:self
action:#selector(myAction:)];
self.navigationItem.rightBarButtonItem = item;
and
- (IBAction)myAction:(id) sender {
MyController *mc = [[MyController alloc] initWithNibName:#"MyController" bundle:nil];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Title" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;

Related

UiNavigationbar buttons not responding after upgrade to iOS 11

After upgrading to iOS 11 and to XCode9 my App's NavigationBar buttons (left and right) are not responding. It is working well in previous version but not in iOS 11. can anybody help me or have faced the same issue. My App is in Objective c language.
**//here is code for leftbarbutton**
UIImage *backSVG = [UIImage imageWithSVGNamed:#"backarrow32" targetSize:CGSizeMake(25, 25) fillColor:[UIColor whiteColor]];
UIBarButtonItem *notifyButton = [[UIBarButtonItem alloc] initWithImage:backSVG style:UIBarButtonItemStylePlain target:self action:#selector(handleBackButton)];
[notifyButton setStyle:UIBarButtonItemStylePlain];
self.navigationItem.leftBarButtonItem = notifyButton;
**//Rightbar buttons are**
UIBarButtonItem *rightbar1 = [[UIBarButtonItem alloc] initWithImage:
[UIImage imageWithSVGNamed:#"rightbar1" targetSize:CGSizeMake(21, 21)
fillColor:[UIColor whiteColor]] style:UIBarButtonItemStylePlain target:self
action:nil];
[rightbar1 setAction:#selector(handlerightbar1Action)];
UIBarButtonItem *rightbar2 = [[UIBarButtonItem alloc] initWithImage:
[UIImage imageWithSVGNamed:#"rightbar2" targetSize:CGSizeMake(21, 21)
fillColor:[UIColor whiteColor]] style:UIBarButtonItemStylePlain
target:self action:nil];
[rightbar2 setAction:#selector(handlerightbar2Action)];
[rightbar1 setImageInsets:UIEdgeInsetsMake(0, -30, 0, -50)];
self.navigationItem.rightBarButtonItems = [NSArray
arrayWithObjects:rightbar2, rightbar1, nil];
Is this navigation bar you added in interface builder or it is from navigation controller (either pushed or root view controller)?
If you can attache an image of the UI view controller from interface builder, it will give more details of the issue.

How to create Previous/Next buttons above keyboard like in Safari

I'm trying to add Previous/Next buttons above the keyboard like in mobile Safari. There are a lot of questions about that here on StackOverflow, but most answers are to use inputAccessoryView.
I tried that and it looks like this:
Is there anyway to have the buttons in the toolbar bellow, like it works in mobile Safari??
This is how it looks like in Safari:
It seems what I was looking for is inputAssistantItem.
It allows you to add and change buttons in the keyboard's shortcut bar.
UIBarButtonItem* nextButton = [[UIBarButtonItem alloc]
initWithImage:nextImage
style:UIBarButtonItemStylePlain
target:self
action:#selector(nextField:)];
UIBarButtonItem* previousButton = [[UIBarButtonItem alloc]
initWithImage:previousImage
style:UIBarButtonItemStylePlain
target:self
action:#selector(previousField:)];
NSArray *buttonGroups = #[[[UIBarButtonItemGroup alloc]
initWithBarButtonItems:#[previousButton, nextButton]
representativeItem:nil]];
textField.inputAssistantItem.trailingBarButtonGroups = buttonGroups;
UIBarButtonItem *previous = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:103 target:self action:#selector(previousButtonTapped:)];
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[fixedSpace setWidth:6.0];
UIBarButtonItem *next = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:104 target:self action:#selector(nextButtonTapped:)];

Custom Back button with image for iOS6+

I'm trying to have a custom back button with image only (no text).
I'm aware that there could be slightly ifferent solution for iOS7 and iOS6. For now I'm not successfull with any.
All I achieved was this:
White default arrow is still there :(
I used this code:
UIImage *temp = [[UIImage imageNamed:#"button_back.png"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:temp style:UIBarButtonItemStyleBordered target:self action:#selector(action)];
[[self navigationItem] setBackBarButtonItem:backButton];
You should use leftBarBttonItem for custom back button
UIImage *temp = [[UIImage imageNamed:#"button_back.png"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:temp style:UIBarButtonItemStyleBordered target:self action:#selector(action)];
self navigationItem.leftBarButtonItem = backButton;

need to change the back button name on navigation bar in ipad

UIBarButtonItem *barBtnItem = [[UIBarButtonItem alloc]initWithTitle:#"Back" style:UIBarButtonItemStyleBordered target:self action:#selector(pop)];
self.navigationItem.backBarButtonItem = barBtnItem;
I placed the above code in iphone it is working.when i am trying it for ipad it is not working.what may be reason?
Thanks in Advance
This changes NavigationBar's BackButton text, to do before pushing a new view controller :
UIViewController *myViewController = [[UIViewController alloc] init];
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"My text" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backBarButtonItem;
[self.navigationController pushViewController:myViewController animated:YES];
And it works for both iPhone and iPad devices.
It looks like you linked your UINavigationController with Interface Builder, you should have a look at this :

How to add buttons to the top bar of a detail view from a UITableView

When an item from a UITableView is selected, a detail view is loaded which has a banner bar at the top with a back button on it to navigate back to the table.
How do I add other buttons to that banner bar?
As Andrew said, you can add custom views to the navigation bar. For example, if you are looking to add multiple buttons to the right side of the navigation bar, you can do something like this:
// right side of nav bar
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 106, 44)];
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:3];
UIBarButtonItem *deleteButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemTrash
target:self
action:#selector(deleteAction:)];
deleteButton.style = UIBarButtonItemStyleBordered;
[buttons addObject:deleteButton];
[deleteButton release];
UIBarButtonItem *spacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
[buttons addObject:spacer];
[spacer release];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:#selector(cancelAction:)];
cancelButton.style = UIBarButtonItemStylePlain;
[buttons addObject:cancelButton];
[cancelButton release];
[toolbar setItems:buttons animated:NO];
toolbar.barStyle = -1;
[buttons release];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
[toolbar release];
Make sure to adjust the width (106 above) if you need more or wider buttons, and then provide methods for the selectors (deleteAction: and cancelAction: above).
From your description, it sounds like you have a UINavigationController correctly set up. That "banner bar" you are describing is properly called a navigation bar.
From within the detail view, you can use:
UIBarButtonItem* button = [[[UIBarButtonItem alloc] initWithTitle:"HiMom" style:UIBarButtonItemStylePlain target:self action:#selector(onHiMom:)] autorelease];
self.navigationItem.rightBarButtonItem = button;
You can also add custom views (instead of a button) plus a few other settings. I suggest poking around the documentation for UINavigationItem, UINavigationBar, and UIBarButtonItem for ideas.

Resources