iOS - 使用StoryBoard创建Popover视图

时间:2011-11-22 10:51:48

标签: ipad ios5 uipopovercontroller xcode4.2 storyboard

您好,现在我正在尝试使用Xcode创建Pop-OverView 故事板。首先,我有

rootViewController, UIViewController, and UITableViewController

我希望UIView充当页面翻转,UITableView将在navigationBar项目控制器下显示popOver。

对于UITableView,我想在NavigationBar控制器下制作Pop-Over。问题是,当我触摸导航项以显示UITableViewController时,它显示正确,但是当我尝试关闭Pop-Over View时,它不会关闭。然后,导航项不能很好地工作。当我多次触摸它时,它会显示popOverView的多个实例。

这对我来说似乎没有意义。任何人都可以帮我或告诉我在哪里可以找到关于此的文档/教程吗?

UPDATE:

对于UIPopOverController,它似乎现在运行良好,但是当我多次触摸导航项时,它仍然在困扰我。它将显示PopOver的多个实例。我该如何处理它,所以它只显示一个实例?

1 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,并且大部分找到了解决方案here。基本上,每次按下按钮以显示或关闭弹出按钮时,您都会更改按钮的动作。这是我最终得到的代码:

@interface FilterTableViewController : UITableViewController {
    UIPopoverController *editPopover;
    id saveEditSender;
    id saveEditTarget;
    SEL saveEditAction;
}

-(void)prepareForSegue:(UIStoryboardPopoverSegue *)segue sender:(id)sender{
    if([[segue identifier] isEqualToString:@"EditFilterSegue"]){
        // Save the edit button's info so we can restore it
        saveEditAction = [sender action];
        saveEditTarget = [sender target];
        saveEditSender = sender;

        // Change the edit button's target to us, and its action to dismiss the popover
        [sender setAction:@selector(dismissPopover:)];
        [sender setTarget:self];

        // Save the popover controller and set ourselves as the its delegate so we can
        // restore the button action when this popover is dismissed (this happens when the popover
        // is dismissed by tapping outside the view, not by tapping the edit button again)
        editPopover = [(UIStoryboardPopoverSegue *)segue popoverController];
        editPopover.delegate = (id <UIPopoverControllerDelegate>)self;
    }
}

-(void)dismissPopover:(id)sender
{
    // Restore the buttons actions before we dismiss the popover
    [saveEditSender setAction:saveEditAction];
    [saveEditSender setTarget:saveEditTarget];
    [editPopover dismissPopoverAnimated:YES];
}

-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
    // A tap occurred outside of the popover.
    // Restore the button actions before its dismissed.
    [saveEditSender setAction:saveEditAction];
    [saveEditSender setTarget:saveEditTarget];

    return YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    // Before we navigate away from this view (the back button was pressed)
    // remove the edit popover (if it exists).
    [self dismissPopover:saveEditSender];
}