开发者

How to dismiss pop over view in content view?

see the screen shot is clear to understand what I mean

How to dismiss pop over view in content view?

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

/**开发者_如何学Go****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)];


While you add the popup view, set tag to that popupView and then, add them as subview,

then use:

for (UIView *tempView in [self.view subviews]) {
    if ([tempView tag]==urTag) {
        [tempView removeFromSuperview];
    }
}

This retrieves all the subviews and then remove only your popupview


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).


 DaysOfWeek *popView = [[DaysOfWeek alloc]init];
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
[doneButton addTarget:self action:@selector(hidePopView) forControlEvents:UIControlEventTouchUpInside];
popView.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:doneButton] autorelease];
UINavigationController *navPopView = [[UINavigationController alloc] initWithRootViewController:popView];

This also can figure out the problem !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜