导航栏中的分段控件
我试图将其放入导航栏中,但没有显示,你可以吗 看看吗?
UISegmentedControl *seg1 = [[UISegmentedControl alloc]
initWithItems:[NSArray arrayWithObjects:@"von mir", @"alle", nil]];
[seg1 setSegmentedControlStyle:UISegmentedControlStyleBar];
UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithCustomView:seg1];
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:self action:nil];
[self.navigationController.navigationBar setItems:[NSArray
arrayWithObjects:flexItem, barItem, flexItem, nil]];
[flexItem release];
[barItem release];
[seg1 release];
I am trying to put this in a navigationbar, but doesnt show up, can u
have a look at it?
UISegmentedControl *seg1 = [[UISegmentedControl alloc]
initWithItems:[NSArray arrayWithObjects:@"von mir", @"alle", nil]];
[seg1 setSegmentedControlStyle:UISegmentedControlStyleBar];
UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithCustomView:seg1];
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:self action:nil];
[self.navigationController.navigationBar setItems:[NSArray
arrayWithObjects:flexItem, barItem, flexItem, nil]];
[flexItem release];
[barItem release];
[seg1 release];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UINavigationBar
的items
属性仅接受UINavigationItem
对象数组,而不接受UIBarButtonItem
对象。您不能像配置UIToolbar
那样配置导航栏。相反,在视图控制器中,执行以下操作:这会将分段控件添加到视图控制器导航项的标题视图中,该导航项是显示在导航栏中央的自定义视图。
UINavigationBar
'sitems
property only accepts an array ofUINavigationItem
objects, notUIBarButtonItem
objects. You can't configure a navigation bar the same way as you do aUIToolbar
. Instead, in your view controller, do this:This adds the segmented control to the title view of your view controller's navigation item, which is a custom view that appears centered on the navigation bar.