推送UIPopOverController的动作

时间:2013-11-19 04:18:31

标签: ios objective-c

我创建了一个弹出窗口来查看我的设置,

if ([popoverController isPopoverVisible]) {
    [popoverController
     dismissPopoverAnimated:YES];
} else {

    UIView* popoverView = [[UIView alloc]
                           initWithFrame:CGRectMake(566, 440, 0, 0)];

    popoverView.backgroundColor = [UIColor blackColor];
    controller1.contentSizeForViewInPopover = CGSizeMake(300, 115);

    popoverController = [[UIPopoverController alloc]
                         initWithContentViewController:controller1];


    [popoverController presentPopoverFromRect:popoverView.frame
                                       inView:self.view
                     permittedArrowDirections:UIPopoverArrowDirectionUp
                                     animated:YES];
}

我的推送操作代码:

UIStoryboard *storyboard = [UIStoryboard
                            storyboardWithName:@"MainStoryboard"
                            bundle:nil];

UIViewController *controller = (UIViewController *)[storyboard
                                                    instantiateViewControllerWithIdentifier:@"PCBViewController"];

[self.navigationController
 pushViewController:controller
 animated:YES];

在我的设置中,popover有一些按钮。单击这些按钮,通过推动操作查看控制器,但它不起作用。

我的问题是:如何为弹出内容设置推送操作。

2 个答案:

答案 0 :(得分:1)

您的视图是从popover呈现的,因此self.navigationController将为nil。

试试这个

UIStoryboard *storyboard = [UIStoryboard
                            storyboardWithName:@"MainStoryboard"
                            bundle:nil];

UIViewController *controller = (UIViewController *)[storyboard
                                                    instantiateViewControllerWithIdentifier:@"PCBViewController"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
[navigationController
 pushViewController:controller
 animated:YES];

答案 1 :(得分:0)

您需要为视图控制器设置导航控制器以允许导航。

你的.h文件中的

UINavigationController *navevent;
UIViewController *yourViewController
<。>在.m文件中合成它并在视图中加载

 navevent=[[UINavigationController alloc]initWithRootViewController:yourViewController];
 yourViewController=[[UIViewController alloc]init];

然后像这样创建你的popover

yourViewController.view = yourView;
 self.popoverController = [[UIPopoverController alloc]initWithContentViewController:navevent] ;

希望这个帮助