Search code examples
iphoneobjective-ciosuipopovercontrollerdismiss

How to dismiss pop over view in content view?


see the screen shot is clear to understand what I mean enter image description here you can see I add a navigationItem in my pop view

I wish I can dismiss the pop view

But it seems only tab the cell under the pop view

The pop view will dismiss,I try to add this method

[self.view removeFromSuperview];

It only remove the table view , the pop view frame is still there ,only without the content view

Any reply will be helpful : )

Thanks

Webber

/******EDIT******/ I use WEPopoverView into my project

And this is the code I create the pop view when I select the table view

if (indexPath.row==2) {
DaysOfWeek *popView = [[DaysOfWeek alloc]init];
UINavigationController *navPopView = [[UINavigationController alloc] initWithRootViewController:popView];
    if (self.popoverController) {
       [self.popoverController dismissPopoverAnimated:YES];
       self.popoverController = nil;
}
else {
        self.popoverController = [[[WEPopoverController alloc] initWithContentViewController:navPopView] autorelease];
        CGRect frame = [tableView cellForRowAtIndexPath:indexPath].frame;
        [self.popoverController presentPopoverFromRect:frame 
                                                    inView:self.view            permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp
                                  animated:YES];
                        }
                    }

/******EDIT2******/ I try to add Done button when I create the pop view here is the code , But it only appear a navigation , no Done button

DaysOfWeek *popView = [[DaysOfWeek alloc]init];
UINavigationController *navPopView = [[UINavigationController alloc] initWithRootViewController:popView];
navPopView.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(hidePopView)];

Solution

  • I think that simply releasing your self.popoverController will do the dismiss properly, including all the superviews.

    You can also have a look at the dealloc method in WEPopoverController to see which views are involved and need to be removed:

        [self dismissPopoverAnimated:NO];
        [contentViewController release];
        [containerViewProperties release];
        [passthroughViews release];
    

    Anyway, the only advantage I see is the possibility of calling dismissPopoverAnimated with YES.

    Hope this helps.

    EDIT:

    How can you connect your done button to your controller?

    Make your button accessible through a read-only property of DaysOfWeek; then in your controller, when you create DaysOfWeek, do:

     DaysOfWeek *popView = [[DaysOfWeek alloc]init];
     [propView.doneButton addTarget:self action:@selector(fullyDismissPopover) forControlEvents:UIControlEventTouchUpInside];
    

    In fullyDismissPopover, you call release or call the sequence of functions highlighted above (but release would be better, I think).