user3674378
user3674378

Reputation: 23

Reloading navigation bar

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.

Upvotes: 0

Views: 1837

Answers (2)

user3206558
user3206558

Reputation: 392

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

Upvotes: 1

user3662854
user3662854

Reputation:

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.

Upvotes: 0

Related Questions