I would like to embed a UISegmentedControl
somewhere in my UINavigationController
s topbar.
It is no problem embedding it in a UIBarBu
Why would you need to put the control in the popover title bar? iPad has much more screen real estate to consider putting it into the view below.
-- EDIT --
I tried it myself and it works. Here is the code setting up the popover controller:
- (IBAction) showPopover: (id) sender
{
TestController *testController = [[TestController alloc] initWithStyle: UITableViewStylePlain];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController: testController];
UIPopoverController *controller = [[UIPopoverController alloc] initWithContentViewController: navController];
[controller presentPopoverFromBarButtonItem: sender permittedArrowDirections: UIPopoverArrowDirectionAny animated: YES];
controller.delegate = self;
[testController release];
[navController release];
}
Here is the implementation of TestController:
- (id) initWithStyle: (UITableViewStyle) style
{
if ( (self = [super initWithStyle: style]) ) {
UISegmentedControl *ctrl = [[UISegmentedControl alloc] initWithFrame: CGRectZero];
ctrl.segmentedControlStyle = UISegmentedControlStyleBar;
[ctrl insertSegmentWithTitle: @"One" atIndex: 0 animated: NO];
[ctrl insertSegmentWithTitle: @"Two" atIndex: 0 animated: NO];
[ctrl insertSegmentWithTitle: @"Three" atIndex: 0 animated: NO];
[ctrl sizeToFit];
// Any of the following produces the expected result:
self.navigationItem.titleView = ctrl;
//self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView: ctrl] autorelease];
[ctrl release];
}
return self;
}
Here is the result:
There are no tricks in my code besides sending sizeToFit
to the segmented control. Does this work for you?