Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

ipad - iOS - Create an Popover View using StoryBoard

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...