iOS - 使用StoryBoard创建Popover视图 [英] iOS - Create an Popover View using StoryBoard

查看:117
本文介绍了iOS - 使用StoryBoard创建Popover视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  rootViewController,UIViewController和UITableViewController 

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



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



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



更新:



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

解决方案

我遇到了同样的问题并且大部分找到了解决方案< a href =https://stackoverflow.com/questions/7758837/uistoryboardpopoversegue-opening-multiple-windows-on-button-touch>这里。基本上,每次按下按钮以显示或关闭弹出按钮时,您都会更改按钮的动作。这是我最终得到的代码:

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

- (void)prepareForSegue:(UIStoryboardPopoverSegue *)segue sender:(id)sender {
if([[segue identifier] isEqualToString:@EditFilterSegue]) {
//保存编辑按钮的信息,以便我们可以恢复它
saveEditAction = [sender action];
saveEditTarget = [发送者目标];
saveEditSender = sender;

//将编辑按钮的目标更改为我们,以及解除弹出窗口的操作
[sender setAction:@selector(dismissPopover :)];
[sender setTarget:self];

//保存popover控制器并将我们自己设置为其委托,这样我们就可以
//当这个popover被解除时恢复按钮动作(当popover
/ /通过点击视图外部来解除,而不是再次点击编辑按钮)
editPopover = [(UIStoryboardPopoverSegue *)segue popoverController];
editPopover.delegate =(id< UIPopoverControllerDelegate>)self;
}
}

- (void)dismissPopover:(id)sender
{
//在我们解除popover $ b之前恢复按钮操作$ b [saveEditSender setAction:saveEditAction];
[saveEditSender setTarget:saveEditTarget];
[editPopover dismissPopoverAnimated:YES];
}

- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
//在弹出窗口外发生了一次点击。
//在解除之前恢复按钮操作。
[saveEditSender setAction:saveEditAction];
[saveEditSender setTarget:saveEditTarget];

返回YES;
}

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

//在我们离开此视图(按下后退按钮)之前,
//删除编辑弹出窗口(如果存在)。
[self dismissPopover:saveEditSender];
}


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?

解决方案

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

这篇关于iOS - 使用StoryBoard创建Popover视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆