转到其他视图后,标签栏按钮顺序已更改

时间:2016-01-27 10:01:36

标签: ios objective-c uibutton uitabbar

我的tabbar中有2个按钮,以编程方式添加。但导航到视图中的另一个占位符后,订单发生了变化。

当我打开应用程序时:
enter image description here
当我进入电影选项卡时:
enter image description here

代码:

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]];

奇怪的是我需要在数组中以错误的顺序添加按钮:_meetupButton,_ searchButton,看起来它改变为正确的顺序。我的问题是如何强制图像始终保持相同的顺序。

1 个答案:

答案 0 :(得分:1)

可能出现问题。但是,要使其正常运行,leftBarButtonItems的{​​{1}}可以按照您分配的navigationItem序列进行排序,而Array的{​​{1}}可以按顺序排列您指定的rightBarButtonItems

也许你可以尝试一下!