iOS - 使用 StoryBoard 创建 Popover 视图

发布于 2024-12-17 15:48:18 字数 549 浏览 1 评论 0原文

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

rootViewController, UIViewController, and UITableViewController

UIView 充当翻页功能,并且 UITableView 将在 navigationBar 项目控制器下显示 popOver。

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

这对我来说似乎没有意义。谁能帮助我或告诉我在哪里可以找到这方面的文档/教程?

更新:

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

Hi there, Now I'm trying to create a Pop-OverView using an Xcode
storyboard. Firstly, I have

rootViewController, UIViewController, and UITableViewController

I want the UIView to act as a page flip and the UITableView will show popOver under the navigationBar item controller.

For the UITableView, I want to make a Pop-Over under NavigationBar controller. The problem is, when I touch the Navigation item to show the UITableViewController, it shows correctly, but when I try to close the Pop-Over View, it won't close. And then, the navigation item doesn't work well. It shows multiple instances of popOverView when I touch it multiple times.

This doesn't seem to make sense to me. Can anyone help me out or tell me where to find documentation / tutorials on this?

UPDATE:

For the UIPopOverController, it seems to work well now, but it is still bugging me when I touch a Navigation Item multiple times. It will show multiple instances of PopOver. How can I handle it, so it will show only one instance?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天涯离梦残月幽梦 2024-12-24 15:48:18

我遇到了同样的问题,并且主要在此处找到了解决方案。基本上,每次按下按钮时,您都会更改按钮的操作以显示或关闭弹出窗口。这是我最终得到的代码:

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

I had the same problem and mostly found the solution here. Basically you change the action of the button each time it's pressed to either display or dismiss the popover. Here's the code I ended up with:

@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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文