0

How can I reload/reassign navigation bar items? I use some libraries that change navigation bar and sometimes I have a bag in which all navigation items disappear. I have reassigned right items in viewWillAppear like:

UIButton *actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
actionButton.frame = CGRectMake(270, 0, 50, 50);
actionButton.adjustsImageWhenHighlighted = YES;
[actionButton setImage:[UIImage imageNamed:@"share.png"] forState:UIControlStateNormal];
[actionButton setImage:[UIImage imageNamed:@"share-active.png"] forState:UIControlStateHighlighted];
[actionButton addTarget:self action:@selector(presentActivity) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *actionBarButton = [[UIBarButtonItem alloc]initWithCustomView:actionButton];
actionBarButton.tintColor = [UIColor whiteColor];
self.navigationItem.rightBarButtonItem = actionBarButton;

But it does not work and sometimes I do not have any navigation items.

4
  • What library are you using? You need to find out at what point the library is messing with your toolbars and call your code after that or prevent it from happening Commented May 26, 2014 at 20:13
  • AMScrollingNavbar, developer of it do not know that happens=/ Commented May 26, 2014 at 20:27
  • Okay, some information from your question is missing. What do you mean by bag? How are you connecting your View Controllers with the Navigation Controller (assuming one Storyboard is being used)? Commented May 26, 2014 at 20:28
  • 1
    I don't think that library is at fault as it is not setting barButtonItems anywhere. Commented May 26, 2014 at 20:31

2 Answers 2

1
UIBarButtonItem

is not child of UIButton.

here is not known methods like setImage:forState: etc.

create and custon an UITabBarButton like this

UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:self action:@selector(goBack)];
    newBackButton.image = [UIImage imageNamed:@"back"];
    self.navigationItem.leftBarButtonItem=newBackButton;

also verify if method with this code will be called when viewDidLoad

Sign up to request clarification or add additional context in comments.

Comments

0

Check out this like https://developer.apple.com/library/ios/documentation/uikit/reference/uinavigationbar_class/Reference/UINavigationBar.html the apple dev is awesome.

This is another good link AppCoda has a lot of great tutorials this one has everything you need to know about Nav Bars http://www.appcoda.com/customize-navigation-status-bar-ios-7/

and you could also use perform segue with identifier method and to send a string or something to a new view controller and then when you see that string is equal to what you want use an if statement in your viewWillAppear method.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.