我的tabbar中有2个按钮,以编程方式添加。但导航到视图中的另一个占位符后,订单发生了变化。
代码:
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,看起来它改变为正确的顺序。我的问题是如何强制图像始终保持相同的顺序。
答案 0 :(得分:1)
可能出现问题。但是,要使其正常运行,leftBarButtonItems
的{{1}}可以按照您分配的navigationItem
序列进行排序,而Array
的{{1}}可以按顺序排列您指定的rightBarButtonItems
。
也许你可以尝试一下!