无法在导航栏的左侧获取分段控件

时间:2011-03-14 15:54:08

标签: objective-c uisegmentedcontrol

我正在尝试以编程方式将UISegementedControl添加到导航栏的左侧。我可以通过将控件设置为titleView来显示它,如下所示。以下是我的代码

NSArray *buttonNames = [NSArray arrayWithObjects:@"One", @"Two", nil];
UISegmentedControl* segmentedControl = [[UISegmentedControl alloc]
segmentedControl.segmentedControlStyle =  UISegmentedControlStyleBar;

// instead of the following I would like to move to left side of the nav bar
self.navigationItem.titleView = segmentedControl;

感谢任何帮助。

1 个答案:

答案 0 :(得分:3)

你试过吗

[[UIBarButtonItem alloc] initWithCustomView:...]


更确切地说,可能是

之类的东西
UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
self.navigationItem.leftBarButtonItem = item;
[item release];