– (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UISegmentedControl *segmentSelector = [[UISegmentedControl alloc] initWithItems:segControlItems];
segmentSelector.segmentedControlStyle = UISegmentedControlStyleBar;
segmentSelector.momentary = NO;
[segmentSelector addTarget:self action:@selector(actionSegmentedIndexChanged:) forControlEvents:UIControlEventValueChanged];
[segmentSelector setWidth:40.0 forSegmentAtIndex:0];
[segmentSelector setWidth:40.0 forSegmentAtIndex:1];

UIBarButtonItem *segButton = [[UIBarButtonItem alloc] initWithCustomView:segmentSelector];
self.navigationItem.rightBarButtonItem = segButton;
}

– (void) actionSegmentedIndexChanged:(id)sender
{
NSLog(@”selectedSegmentIndex: %d”, segmentSelector.selectedSegmentIndex);

}