容器视图弹出视图以编程方式

时间:2014-05-13 03:37:35

标签: view popover uicontainerview

在iPad视图中我添加了Container View,添加Xcode后自动创建新视图并使用embed segue连接到我的主视图。现在在代码中我尝试以编程方式调用这个新视图而不能这样做,我需要用popover显示这个表单。

我试试:

PaymentCashController *newPopup = [self.storyboard   instantiateViewControllerWithIdentifier:@"PaymentCash"];
[self presentViewController:newPopup animated:YES completion:nil];

这项工作但全屏显示新视图,但我需要使用popover显示。我尝试了许多事情而且都没有工作(。

我试试这个:

[self performSegueWithIdentifier:@"PaymentCash" sender:nil];

但是收到SIGABRT异常

我试试这个:

    PaymentCashController *newPopup = [self.storyboard instantiateViewControllerWithIdentifier:@"PaymentCash"];

    UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:newPopup];

    popoverController.popoverContentSize = CGSizeMake(500, 400);

    CGRect popoverStartFrame = {50, 500, 100, 100};//Set the frame that you would like your popover to present from.
    [popoverController presentPopoverFromRect: popoverStartFrame inView:self.view  permittedArrowDirections: UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionUp animated:YES];

接收SIGABRT异常

试试这个:

    PaymentCashController *newPopup = [PaymentCashController new];

    UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:newPopup];

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

    [popoverController presentPopoverFromRect:CGRectMake(44, 6, 111, 111) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

相同的SIGABRT

2 个答案:

答案 0 :(得分:0)

您需要使用视图控制器创建UIPopoverController并显示弹出窗口,如下所示。

PaymentCashController *newPopup = [self.storyboard   instantiateViewControllerWithIdentifier:@"PaymentCash"];

UIPopoverController *popoverController = [[UIPopoverController alloc] newPopup];
popover.delegate = self;
//set custom size you want for popover
popover.popoverContentSize = CGSizeMake(500, 400); 
CGRect popoverStartFrame = {50, 500, 100, 100};//Set the frame that you would like your popover to present from.
[popover presentPopoverFromRect: popoverStartFrame inView:self.view permittedArrowDirections: UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionUp animated:YES];

答案 1 :(得分:0)

许多实验,现在都在工作:

  1. 将所有segue移除到Storyboard中的弹出视图。做它自由形式并改变大小。
  2. 添加到我的主要查看新属性

    @property(非原子,强)UIPopoverController * popOver;

  3. 将故事板ID设置为我的popover查看" PaymentCash"。

  4. 在我的View上显示我的popover View的任何操作中添加以下代码:

    PaymentCashController *PopoverView = [self.storyboard instantiateViewControllerWithIdentifier:@"PaymentCash"];
    self.popOver =[[UIPopoverController alloc] initWithContentViewController:PopoverView];
    CGRect popoverStartFrame = {1,500,200,1};
    [self.popOver presentPopoverFromRect:popoverStartFrame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
    
  5. 此后只有一个问题,popover View显示在正确的位置,但这是另一个问题。