我有一个地图视图,我annotations
根据popovercontroller
. 当我在外部触摸时popover
,它会正确关闭并调用该delegate
方法popoverControllerDidDismissPopover:
我遇到的问题是,当我在popover
(在弹出窗口视图中触摸)切换开关时,如果我annotations
从地图中删除它,它的行为正确并且弹出窗口保持可见,但如果我将其添加annotations
到地图视图中,则会popover
消失并且delegate
不会调用该方法。有没有人遇到过这种行为?
开关的 on 和 off 代码之间的唯一区别是一个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];
}
这是从弹出视图中调用的方法:
-(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];
}
}
}
}