Ipad 在故事板中布局视图,然后从代码中加载到弹出框中?

Ipad 在故事板中布局视图,然后从代码中加载到弹出框中?,ipad,ios5,storyboard,uipopovercontroller,Ipad,Ios5,Storyboard,Uipopovercontroller,我有一个相对复杂的ui出现在一个弹出窗口中(复杂到从代码中执行所有布局和关系都会很痛苦),但是调用它的按钮是从代码中创建并放置到父视图(存在于故事板中)中的 我尝试过从父视图的viewcontroller对象到popover内容vc创建一个popover segue,然后使用PerformsgueWithIdentifier触发它。这几乎可以实现,但我不知道如何通过代码设置popOver的锚点,使其出现在错误的位置(挤压在屏幕底部) 有没有办法动态设置popOver segue的锚点? 或 我可

我有一个相对复杂的ui出现在一个弹出窗口中(复杂到从代码中执行所有布局和关系都会很痛苦),但是调用它的按钮是从代码中创建并放置到父视图(存在于故事板中)中的

我尝试过从父视图的viewcontroller对象到popover内容vc创建一个popover segue,然后使用PerformsgueWithIdentifier触发它。这几乎可以实现,但我不知道如何通过代码设置popOver的锚点,使其出现在错误的位置(挤压在屏幕底部)

有没有办法动态设置popOver segue的锚点? 或 我可以创建一个UIPopOverController对象并将我在故事板中放在一起的视图放到其中吗? 或 有没有其他我没有看到的显而易见的方法

请温柔点,我是新来的

iPad iOS5.1 XCode4.3.2

我不完全确定我是否理解你的意图,但让我从我认为我理解的角度来尝试一下

出于您引用的相同原因(视图复杂性等),我经常在故事板中构建视图,然后从某些操作加载它们。您可以通过标识符实例化视图控制器,如下所示:

FancyViewController *controller = [[self storyboard] 
              instantiateViewControllerWithIdentifier:@"FancyViewController"];
- (IBAction)didTapButtonToShowFancyViewController:(id)sender
{
  if (![self fancyViewController])
  {
    // fancyViewContrller is a property of type FancyViewController *
    fancyViewController = [[[self storyboard]
          instantiateViewControllerWithIdentifier:@"FancyViewController"];

    // fancyViewPopoverController is also a property
    fancyViewPopoverController = [[UIPopoverController alloc] 
                  initWithContentViewController:fancyViewController];
  }

  // Perform setup on the fancy controller you want to do every
  // time the action gets triggered here. Do initialization in the if
  // block above.

  // Now display the popover from the sender's frame. I'm assuming the
  // sender is a UIButton.
  [fancyViewPopoverController presentPopoverFromRect:[sender valueForKey:@"frame"] 
                              inView:[self view] 
              permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}
这假设您已经创建了一个名为FancyViewController的UIViewController子类,并在情节提要中设置了视图控制器的类型

现在,您可以在popover控制器中显示视图控制器,也可以将其推送到导航堆栈上。您只需确保已在情节提要中为视图控制器设置了标识符

此外,如果使用popover控制器,并且每次触发操作时只更新视图控制器属性,则可能需要实例化视图控制器一次。因此,如果点击触发弹出框的按钮,您的代码可能如下所示:

FancyViewController *controller = [[self storyboard] 
              instantiateViewControllerWithIdentifier:@"FancyViewController"];
- (IBAction)didTapButtonToShowFancyViewController:(id)sender
{
  if (![self fancyViewController])
  {
    // fancyViewContrller is a property of type FancyViewController *
    fancyViewController = [[[self storyboard]
          instantiateViewControllerWithIdentifier:@"FancyViewController"];

    // fancyViewPopoverController is also a property
    fancyViewPopoverController = [[UIPopoverController alloc] 
                  initWithContentViewController:fancyViewController];
  }

  // Perform setup on the fancy controller you want to do every
  // time the action gets triggered here. Do initialization in the if
  // block above.

  // Now display the popover from the sender's frame. I'm assuming the
  // sender is a UIButton.
  [fancyViewPopoverController presentPopoverFromRect:[sender valueForKey:@"frame"] 
                              inView:[self view] 
              permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}
动态设置popover的“锚定”的唯一方法是使用显式操作,该操作调用
presentPopoverFromRect:permittedArrowDirections:animated:
,而不是segue

我希望这有帮助。如果我误解了你的意图,请告诉我


致以最诚挚的问候。

嘿,马特,我想我需要使用presentPopoverFromRect,但不知道如何从故事板实例化视图控制器。我会尽量澄清我的问题!谢谢