UIPopover中的导航栏

时间:2011-02-15 11:01:07

标签: cocoa-touch ipad uitableview uisplitviewcontroller uipopovercontroller

在我的splitviewcontroller iPad应用程序中,我显示了一个自定义弹出窗口(加载rootviewController)。如何不仅显示表格视图,还显示其上方的导航栏(以显示表格标题“类别”)。

这是我的应用:

enter image description here

我的代码显示popover:

- (IBAction)showPopover:(UIButton *)sender {
if([self.popoverController isPopoverVisible])
{
    [self.popoverController dismissPopoverAnimated:YES];
    return;
}

// Build a custom popover view
TemplatesAppDelegate *delegate = (TemplatesAppDelegate*)[[UIApplication sharedApplication] delegate];

// Create a popover controller
self.popoverController = [[[UIPopoverController alloc] initWithContentViewController:delegate.rootViewController] autorelease];

// Present the popover view non-modal at the pressed button's position
[self.popoverController presentPopoverFromRect:sender.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}

2 个答案:

答案 0 :(得分:1)

如果你想要一个具有所有功能的整个UINavigationController,你可以这样做

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:delegate.rootViewController];

self.popoverController = [[[UIPopoverController alloc] initWithContentViewController:navController] autorelease];
[navController release];

或者如果你只想要一个导航栏,你可以添加到你的popovercontroller。

UINavigationBar *tableViewNavigationBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
[self.popoverController addSubView:tableViewNavigationBar];

我没有对代码进行测试,但它应该可以运行。

答案 1 :(得分:0)

你可以试试这个:

CNYAssetTypeViewController *avc=[[CNYAssetTypeViewController alloc] init];
if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPad){
    UINavigatinoController *nv=[[UINavigationController alloc]initWithRootViewController:avc];
    self.assetTypeControllerPopover=[[UIPopOverController alloc]initWithContentViewController:nv];
    self.assetTypeControllerPopover.delegat=self;
    avc.title=@"CNY";
    [self.assetTypeControllerPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopOverArrowDirectionAny animated:YES];
}else{
    [self.navigationController pushViewController:avc animated:YES];    
}