为什么需要将控件放在弹出框标题栏中?iPad 有更多的屏幕空间可以考虑将其放入下面的视图中。
- 编辑 -
我自己尝试过,它有效。这是设置弹出框控制器的代码:
- (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];
}
下面是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;
}
结果如下:
除了发送sizeToFit
到分段控件之外,我的代码中没有任何技巧。这对你有用吗?