我的工具栏中有许多BarButtons,我想为每个UIPopoverController显示不同的for。当我点击它们中的一个时,其他PopoverControllers应该会被清除(即屏幕上只显示一个the控制器)。我不想保留对它们的引用--因为这太烦人了。有没有其他方法可以打发他们呢?
谢谢。
发布于 2011-03-07 17:44:51
据我所知,没有“关闭所有弹出窗口”功能。
但要解决这个问题,您不必保留对所有不同弹出窗口的引用;只需保留对当前显示的弹出窗口的引用。然后当一个新的弹出窗口启动时,你可以忽略当前显示的弹出窗口(如果它不是空的)。然后将“当前正在显示弹出窗口”指定给您显示的新弹出窗口。
发布于 2013-02-04 20:20:06
使用自动化测试框架KIF使我产生了查看其dismissPopovers函数的想法。
我稍微修改了一下这个函数,这样你就可以使用全局消除所有弹出窗口的功能了。代码如下:
//dismiss popovers
NSArray *windows = [[UIApplication sharedApplication] windows];
for(UIView *currentPopover in [[windows objectAtIndex:0] subviewsWithClassNamePrefix:@"UIDimmingView"]) {
[currentPopover removeFromSuperview];
}和UIViewExtension:
- (NSArray *)subviewsWithClassNamePrefix:(NSString *)prefix;
{
NSMutableArray *result = [NSMutableArray array];
// Breadth-first population of matching subviews
// First traverse the next level of subviews, adding matches.
for (UIView *view in self.subviews) {
if ([NSStringFromClass([view class]) hasPrefix:prefix]) {
[result addObject:view];
}
}
// Now traverse the subviews of the subviews, adding matches.
for (UIView *view in self.subviews) {
NSArray *matchingSubviews = [view subviewsWithClassNamePrefix:prefix];
[result addObjectsFromArray:matchingSubviews];
}
return result;}
感谢KIF的提示
发布于 2011-03-07 17:48:45
根据来自的开发人员文档,在popover内容之外的点击会自动关闭popover。但是,您可以使用此方法dismissPopoverAnimated以编程方式关闭弹出窗口,以响应弹出窗口window.Like内的点击。例如,您可以在UIImagePickerController的didFinishPickingMediaWithInfo委托中关闭它
希望你得到it...Good幸运!
https://stackoverflow.com/questions/5217895
复制相似问题