开发者

segmentedcontrol in navigationbar

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:se开发者_JS百科g1];
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];


UINavigationBar's items property only accepts an array of UINavigationItem objects, not UIBarButtonItem objects. You can't configure a navigation bar the same way as you do a UIToolbar. Instead, in your view controller, do this:

UISegmentedControl * seg1 = [[UISegmentedControl alloc]
    initWithItems:[NSArray arrayWithObjects:@"von mir", @"alle", nil]];
[seg1 setSegmentedControlStyle:UISegmentedControlStyleBar];
self.navigationItem.titleView = seg1;

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜