如何在内容视图中关闭弹出视图?

发布于 2024-11-17 20:54:43 字数 1762 浏览 2 评论 0原文

看屏幕截图很清楚明白我的意思 在此处输入图像描述 你可以看到我在弹出视图中添加了一个导航项目

我希望我可以关闭弹出视图

但似乎只能选择弹出视图下的单元格

弹出视图将关闭,我尝试添加此方法

[self.view removeFromSuperview];

它只删除表格视图,弹出视图框架仍然存在,只是没有内容视图

任何回复都会有帮助:)

谢谢

Webber

/*****编辑*****/ 我在我的项目中使用 WEPopoverView

这是我创建弹出视图时的代码选择表视图

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*****/ 我尝试在创建弹出视图时添加“完成”按钮 这是代码,但只出现了一个导航,没有完成按钮

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

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

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

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

发布评论

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

评论(3

梦里泪两行 2024-11-24 20:54:43

添加弹出视图时,将标记设置为该弹出视图,然后将它们添加为子视图,

然后使用:

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

这会检索所有子视图,然后仅删除您的弹出视图

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

舟遥客 2024-11-24 20:54:43

我认为只需释放您的 self.popoverController 即可正确关闭,包括所有超级视图。

您还可以查看 WEPopoverController 中的 dealloc 方法,看看涉及哪些视图并需要删除:

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

无论如何,我看到的唯一优点是可以调用dismissPopoverAnimatedYES

希望这有帮助。

编辑:

如何将完成按钮连接到控制器?

使您的按钮可通过 DaysOfWeek 的只读属性进行访问;然后在您的控制器中,当您创建 DaysOfWeek 时,执行以下操作:

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

在 fullDismissPopover 中,您调用release或调用上面突出显示的函数序列(但我认为release会更好)。

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

秋千易 2024-11-24 20:54:43
 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];

这样也能搞清楚问题了!

 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 !

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