我有一个地图视图,我根据annotations
中的切换添加和删除popovercontroller
。当我在popover
之外触摸时,它会正确解散并调用delegate
方法popoverControllerDidDismissPopover:
我遇到的问题是当我切换popover
中的切换时(触摸)在弹出窗口视图中),如果我从地图中删除annotations
它的行为正确并且弹出窗口保持可见但是如果我将annotations
添加到地图视图中,则popover
消失,并且不调用delegate
方法。有没有人遇到过这种行为?
交换机的开启和关闭代码之间的唯一区别是,一个从数组中删除annotations
,而另一个添加annotations
。将annotations
添加到地图视图时,这只是一个问题。任何帮助或建议将不胜感激。
这是显示popover
的方式:
-(IBAction)toggleMapFiltersView:(id)sender
{
LayerPopoverViewController *popOverViewController = [[LayerPopoverViewController alloc] init];
[popOverViewController setDelegate:self];
[popOverViewController setBranchesShowing:branchesShowing];
[popOverViewController setSchoolsShowing:schoolsShowing];
[layersButton setSelected:YES];
popoverController = [[UIPopoverController alloc] initWithContentViewController:popOverViewController];
[popoverController setDelegate:self];
[popOverViewController release];
[popoverController presentPopoverFromRect:layersButton.frame
inView:[self view]
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
这是从popover视图调用的方法:
-(IBAction)toggleSchools:(id)sender
{
if ([self.delegate respondsToSelector:@selector(didChangeSchoolsDisplaySettingWithVisible:)])
{
if ([schoolsSwitch isOn])
{
[self.delegate didChangeSchoolsDisplaySettingWithVisible:YES];
self.schoolsShowing = YES;
}
else
{
[self.delegate didChangeSchoolsDisplaySettingWithVisible:NO];
self.schoolsShowing = NO;
}
}
}
这就是它所指的方法:
-(void)didChangeSchoolsDisplaySettingWithVisible:(BOOL)visible
{
if (visible == YES)
{
schoolsShowing = YES;
if (self.schoolArray != nil && [self.schoolArray count] > 0)
{
for (MySchool *school in self.schoolArray)
{
[mapView addAnnotation:school];
}
}
}
else
{
schoolsShowing = NO;
for (id<MKAnnotation> annotation in mapView.annotations)
{
if ([annotation isKindOfClass:[MySchool class]])
{
[mapView removeAnnotation:annotation];
}
}
}
}
答案 0 :(得分:0)
为什么首先使用popovers?它可以让您更轻松地控制customView。
您可以创建自定义popupView,并将其放在您喜欢的坐标上方。 弹出窗口有一个关闭按钮,并委托调用此操作。
这里有一些代码(在这个例子中,坐标来自标记,mapView是google&#39; s)。您还必须将坐标转换为CGPoint。
UIAnnotationView *annotation = [[UIAnnotationView alloc] initWithFrame:CGRectMake(0,0,100,100)];
annotation.delegate = self;
annotation.tag = 101;
CGPoint point = [mapView.projection pointForCoordinate:marker.position];
annotation.origin = CGPointMake(point.x - annotation.width / 2, point.y - annotation.height - MARKER_DEFAULT_SIZE);
[mapView addSubview:annotation];
UIAnnotaionView closeButtonClicked委托:
- (void)annotationViewCloseButtonClicked:(UIAnnotationView *)annotationView
{
[[_mapView viewWithTag:101] removeFromSuperview];
}
要在触摸地图中的其他点时关闭popupView,请覆盖此委托:
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
{
[[_mapView viewWithTag:101] removeFromSuperview];
}
答案 1 :(得分:0)
您是否尝试了另一种委托方法
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController {
// do some stuff here and decide whether to dismiss or not
return YES; //or No depending on your condition
}
它会询问您是否要关闭popOver控制器。 每次popoverviewcontroller即将解散时都会调用它
否则,您可以在向mapview添加注释时调用方法。无论如何,你知道流行音乐正在消失。当弹出控制器解散时执行相同的工作。正如你所做的那样
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
我希望这可以帮到你