使用“后退”按钮在导航栏中进行UISegmentedControl [英] UISegmentedControl in the Navigation Bar with the Back button
问题描述
我正在以编程方式将 UISegmentedControl
添加到导航栏,其中 titleView
应该是。但是, Apple docs 已提到在 titleView
下,如果leftBarButtonItem不是nil ,则忽略此属性。
I'm adding a UISegmentedControl
to the Navigation bar programatically where the titleView
should be. But as Apple docs have mentioned under titleView
, This property is ignored if leftBarButtonItem is not nil.
但是我想要也有后退按钮。就像他们在自己的图像中说明一样!
But I want to have the back button as well. Like they have illustrated in their own images!
以下是我添加 UISegmentedControl
的代码。
self.navigationItem.leftBarButtonItem = nil;
UISegmentedControl *statFilter = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Filter_Personnal", @"Filter_Department", @"Filter_Company", nil];
[statFilter setSegmentedControlStyle:UISegmentedControlStyleBar];
self.navigationItem.titleView = statFilter;
还有另一种方法可以添加 UISegmentedControl
还有后退按钮?
Is there another way to add a UISegmentedControl
along with the Back button as well?
谢谢。
推荐答案
试试这个
删除这一行---> self.navigationItem.leftBarButtonItem = nil;
Remove this line --- > self.navigationItem.leftBarButtonItem = nil;
添加此项
UISegmentedControl *statFilter = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Filter_Personnal", @"Filter_Department", @"Filter_Company", nil]];
[statFilter setSegmentedControlStyle:UISegmentedControlStyleBar];
[statFilter sizeToFit];
self.navigationItem.titleView = statFilter;
只有更改是我添加了这一行:
Only change is I have added this line :
[statFilter sizeToFit];
希望这有助于!!!
这篇关于使用“后退”按钮在导航栏中进行UISegmentedControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!