Right bar button not appearing in iphone 6 and 6+
Asked Answered
O

3

7

I am trying to add a Right bar button in my tabbar's navigationbar, and its working fine in iphone 5 and 5s device and all simulators. But its not showing up in iphone 6 and 6+ device.However its working fine on simulator of iphone 6 and 6+.

Here is the button code.

@property (nonatomic, weak) UIButton *rightButton;



-(void)setNavigationBarRightButton
{


    rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    rightButton.frame = CGRectMake(0, 0, 40, 40);
    rightButton.layer.cornerRadius = 20;
    rightButton.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    rightButton.layer.borderWidth = 2;
    rightButton.imageView.layer.cornerRadius = 20;
    rightButton.clipsToBounds = YES;




    UIImage* image;

    NSData* imageData = [[NSUserDefaults standardUserDefaults] objectForKey:@"image"];


    if (imageData == (id)[NSNull null] || imageData.length == 0) {
        NSLog(@"image data is %@",imageData);
        image = [UIImage imageNamed:@"defaultIcon.png"];
    }
    else {
        image = [UIImage imageWithData:imageData];

    }

    // rightButton.imageView.image = image;
    [rightButton setBackgroundImage:image forState:UIControlStateNormal];

    [rightButton addTarget:self action:@selector(onClickrighttButton:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];

    self.tabBarController.navigationItem.rightBarButtonItem = rightBarButtonItem;




}

- (void)onClickrighttButton:(id)sender
{
    NSLog(@"clicked");

}

You can see in the image as wellenter image description here

Also a clear image of iphone 6 enter image description here

See there is even no place holder appear as the button have a border of 2.

Oppose answered 29/6, 2015 at 8:21 Comment(9)
Did you try to clean the project and possibly the derived data ?Grubbs
You shouldn't hold a weak reference. Try @property (nonatomic) UIButton *rightButton;Rolf
Off the top of my head, I think you should set it on the view controller itself, not the tab bar controller. Or is your hierarchy actually Nav > Tab > Content?Rickey
I guess you have not settled up the Launch screen for iPhone 6 and 6+. Add it and try now.Luncheonette
I have the launch screen for both 6 and 6+Oppose
@ChristianSchnorr yeahOppose
@SaadChaudhry I think you should rethink your hierarchy then. Typically the tab bar controller is top-level.Rickey
yes but I have the sign in like stuff before that.Oppose
Any Solution to this? I am facing same issue but in iPad!Gerigerianna
G
1

1) If you are using Autoresizing Sub-Mask check Whether you have set the 'Autoresizing Mask' properly, [Check in Preview].

2) If you are using Size class then make sure about the constraints you have set, [Check in Preview].

3) Second thing if its not working by any way and you are in hurry, Simply use your custom header view instead of navigation bar with custom buttons on right and left.

Goldman answered 29/6, 2015 at 9:38 Comment(0)
J
0

Use below code.

 UIImage* searchImage = [UIImage imageNamed:@"search.png"];
 CGRect searchFraming = CGRectMake(30, 30, 25, 26);
 UIButton *searchButton = [[UIButton alloc] initWithFrame:searchFraming];
 [searchButton setBackgroundImage:searchImage forState:UIControlStateNormal];
 [searchButton addTarget:self action:@selector(searchButtonClicked)
           forControlEvents:UIControlEventTouchUpInside];
 [searchButton setShowsTouchWhenHighlighted:YES];
 UIBarButtonItem *searchButtonBarItem =[[UIBarButtonItem alloc] initWithCustomView:searchButton];
 [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:locationButtonBarItem ,nil]];
Jobe answered 30/6, 2015 at 9:37 Comment(0)
M
0

You can use view debugging (Debug View Hierarchy) to check, where your button is gone. Just click on the device icon on the top of your debugging / log area

Microspore answered 30/6, 2015 at 9:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.