0

在 iPad 视图中,我添加了容器视图,添加 Xcode 后自动创建新视图并使用嵌入 segue 连接到我的主视图。现在在代码中我尝试以编程方式调用这个新视图并且不能这样做,我需要用弹出框显示这个表单。

我尝试:

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

这项工作,但全屏显示新视图,但我需要显示弹出窗口。我尝试了很多东西,但都不起作用(。

我试试这个:

[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

4

2 回答 2

0

Many experiments and now all working:

  1. Remove all segue to my popover View in Storyboard. Do it freeform and change size.
  2. Add to my main View new property

    @property (nonatomic,strong) UIPopoverController *popOver;

  3. Set storyboard id to my popover View to "PaymentCash".

  4. In any action on my View to show my popover View add this code:

    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];
    

Only one problem after this, popover View show in no correct place but this another question.

于 2014-05-14T04:36:53.027 回答
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];
于 2014-05-13T03:49:20.587 回答