UiNavigationbar buttons not responding after upgrade to iOS 11 - ios

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.

Related

In iOS 11 Navigation item's titleview, barbutton items are not displaying (Using Xcode 9)

Working in a iPad application(Objective-c), which showed the navigation item's titleview, barbuttonitems in previous iOS versions. But it is not displaying in iOS 11 (Using Xcode 9). I'm using xib not storyboard.
self.editButton = [[UIBarButtonItem alloc] initWithTitle:#"Create Call" style:UIBarButtonItemStylePlain target:self action:#selector(accountView:)];
[self.editButton setTitleTextAttributes:attributes forState:UIControlStateNormal];
self.deleteCallButton = [[UIBarButtonItem alloc] initWithTitle:#"Delete" style:UIBarButtonItemStylePlain target:self action:#selector(deleteCall:)];
[self.deleteCallButton setTitleTextAttributes:attributes forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:sliderBarItem, self.deleteCallButton, self.emptySeparatorButton1, self.editButton, self.emptySeparatorButton2, self.createOrderButton, nil];

UIBarButton Deprecated in IOS 8.0

After changing the deployment target from 7.1 to 8.2, I just got a warning telling me that UIBarButton is deprecated.
Here is the code that I use:
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:#"Done" style:UIBarButtonItemStyleBordered target:self action:#selector(nextButton)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], nil];
self.numberOfGuestsTextField.inputAccessoryView = numberToolbar;
Is there anything that I can use instead of UIBarButtonItem
UIBarButtonItem is not deprecated - UIBarButtonItemStyleBordered is. Just use UIBarButtonItemStylePlain or UIBarButtonItemStyleDone instead.
As of iOS 7, the style of bar buttons has changed to a more flat form. That's why UIBarButtonItemStyleBordered is no longer available - it just looks like a UIBarButtonItemStylePlain button. With UIBarButtonItemStyleDone, the text will be bold instead of regular.

UIBarButtonItem disappears

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;

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;

How do i remove text from back button on navbar within Xcode?

I set an arrow custom image to navigation bar by adding the following code in app delegate, it works but now im looking to remove the text completely for back button.
UIImage * backButtonImage = [UIImage imageNamed: #"BackButtonGrey.png"];
backButtonImage = [backButtonImage stretchableImageWithLeftCapWidth: 15.0 topCapHeight: 30.0];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage: backButtonImage forState: UIControlStateNormal barMetrics: UIBarMetricsDefault];
Simply move the text vertically so far that it no longer appears. This can be done at app launch in your app delegate.
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, 20.f) forBarMetrics:UIBarMetricsDefault];
Normally this call is for tweaking the vertical text position which can vary depending on the font used. Here the text is moved far enough that it's no longer inside the Back button view, and so is clipped into non-existence.
I really don't think is a good practice for a developer to adjust the offset of the text in order to hide it.
A cleaner solution would be to just add to the navigation controller back button a new button where the title is an empty string. You should add this in the previous calling view controller in viewWillAppear (not the current one):
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-100.f, 0) forBarMetrics:UIBarMetricsDefault];
I just did it like this, worked fine for me :-)
UIImage *backButtonImage = [UIImage imageNamed:#"navigationBarBack.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:backButtonImage
forState:UIControlStateNormal];
backButton.frame = CGRectMake(0, 0, backButtonImage.size.width, backButtonImage.size.height);
[backButton addTarget:self
action:#selector(popViewController)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = backBarButtonItem;
Do not use the appearance proxy. Instead, for every view controller, put this code into its viewDidLoad implementation:
UIImage * backButtonImage =
[UIImage imageNamed: #"BackButtonGrey.png"];
backButtonImage =
[backButtonImage stretchableImageWithLeftCapWidth: 15.0 topCapHeight: 30.0];
UIBarButtonItem* b =
[[UIBarButtonItem alloc]
initWithImage:backButtonImage
style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = b;
That will cause the next view controller pushed onto the navigation stack to have a back button consisting of just the image.
(However, I should point out that stretchableImageWithLeftCapWidth:... is deprecated. You should be using resizableImage....)
To set a backbutton text, you set a new backbutton to the current viewController before pushing or presenting then new one which would show the text of the backbutton:
In your current viewController (not the new one which will show the back-button):
vc = [[MyNewViewController alloc]initWith...];
vc.title = #"New ViewController";
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
[self.navigationController pushViewController:vc animated:YES];
So if you want to remove the text, just use #"" as a title for the new backbutton.
To set a backbutton-icon for the entire app, use the following code in your appDelegate class. Not every icon fits perfectly, so if you have to move it around a little, you can use the "backInsets". In my example the icon will move 2px down.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
...
[self customBackButtonIcon];
return YES;
}
- (void)customBackButtonIcon
{
UIEdgeInsets backInsets = UIEdgeInsetsMake(0, 0, -2, 0);
UIImage *backImg = [[[UIImage imageNamed:#"back_button_white"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] imageWithAlignmentRectInsets:backInsets];
[[UINavigationBar appearance] setBackIndicatorImage:backImg];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backImg];
}
Tested with iOS9
UIBarButtonItem *newBackButton =
[[UIBarButtonItem alloc] initWithTitle:#""
style:UIBarButtonItemStylePlain
target:nil
action:nil];
[[self navigationItem] setBackBarButtonItem:newBackButton];
Perfect solution globally
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.clearColor()], forState: UIControlState.Normal)
UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.clearColor()], forState: UIControlState.Highlighted)
return true
}

Resources