I have 2 buttons in my tabbar, programmatically added. But the order changed after navigating to another placeholder within the view.
When I open the app:
When I go to the movies tab:
The code:
self.searchButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(toggleSearchBar)];
UIImage* meetupButtonIcon = [UIImage imageNamed:@"meetup_logo_icon"];
UIImage* meetupButtonIconHighlighted = [UIImage imageNamed:@"meetup_logo_icon_highlighted"];
CGRect frameimg = CGRectMake(0, 0, 25, 25);
UIButton *meetupUIButton = [[UIButton alloc] initWithFrame:frameimg];
[meetupUIButton setBackgroundImage:meetupButtonIcon forState:UIControlStateNormal];
[meetupUIButton setBackgroundImage:meetupButtonIconHighlighted forState:UIControlStateHighlighted];
[meetupUIButton addTarget:self action:@selector(toggleMeetup:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *meetupIcon =[[UIBarButtonItem alloc] initWithCustomView:meetupUIButton];
self.meetupButton = meetupIcon;
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:_meetupButton, _searchButton, nil]];
The strange thing is I need to add the buttons in the wrong order in the array: _meetupButton, _searchButton and looks like it change to the right order. My question how to force the images to be always in the same order.
Something maybe goes wrong. However to get it working, leftBarButtonItems
of navigationItem
can be ordered with sequence of Array
which you assign and rightBarButtonItems
of navigationItem
can be ordered with inverted sequence of Array
which you assign.
Maybe you can give it a try!