如何在内容视图中关闭弹出视图?
看屏幕截图很清楚明白我的意思 你可以看到我在弹出视图中添加了一个导航项目
我希望我可以关闭弹出视图
但似乎只能选择弹出视图下的单元格
弹出视图将关闭,我尝试添加此方法
[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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
添加弹出视图时,将标记设置为该弹出视图,然后将它们添加为子视图,
然后使用:
这会检索所有子视图,然后仅删除您的弹出视图
While you add the popup view, set tag to that popupView and then, add them as subview,
then use:
This retrieves all the subviews and then remove only your popupview
我认为只需释放您的 self.popoverController 即可正确关闭,包括所有超级视图。
您还可以查看
WEPopoverController
中的dealloc
方法,看看涉及哪些视图并需要删除:无论如何,我看到的唯一优点是可以调用
dismissPopoverAnimated
为YES
。希望这有帮助。
编辑:
如何将完成按钮连接到控制器?
使您的按钮可通过
DaysOfWeek
的只读属性进行访问;然后在您的控制器中,当您创建 DaysOfWeek 时,执行以下操作:在 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 inWEPopoverController
to see which views are involved and need to be removed:Anyway, the only advantage I see is the possibility of calling
dismissPopoverAnimated
withYES
.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 createDaysOfWeek
, do:In fullyDismissPopover, you call release or call the sequence of functions highlighted above (but release would be better, I think).
这样也能搞清楚问题了!
This also can figure out the problem !