gpt4 book ai didi

iphone - UIPopoverController 在没有委托(delegate)调用的情况下解散

转载 作者:技术小花猫 更新时间:2023-10-29 11:08:53 25 4
gpt4 key购买 nike

我有一个 map View ,我根据 popovercontroller 中的开关添加和删除 annotations。当我触摸 popover 外部时,它会正确关闭并调用 delegate 方法 popoverControllerDidDismissPopover: 我遇到的问题是,当我切换在 popover 中切换(在 popover View 中触摸),如果我从 map 中删除 annotations 它的行为正确并且 popover 保持可见但如果我添加 annotations 到 map View ,然后 popover 消失并且 delegate 方法不被调用。以前有人遇到过这种行为吗?

开关的 on 和 off 代码之间的唯一区别是,一个从数组中删除 annotations,而另一个添加 annotations。这只是在将 annotations 添加到 map View 时出现的问题。如有任何帮助或建议,我们将不胜感激。

这是 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];
}

这是从弹出 View 调用的方法:

-(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];
}
}
}
}

最佳答案

为什么首先使用弹出窗口?您可以更轻松地控制自定义 View 。

您可以创建一个自定义的 popupView,并将其放置在您喜欢的坐标之上。弹出窗口有一个关闭按钮,并委托(delegate)调用此操作。

这是一些代码(在这个例子中,坐标来自一个标记,而 mapView 是谷歌的)。您还必须将坐标转换为 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 委托(delegate):

- (void)annotationViewCloseButtonClicked:(UIAnnotationView *)annotationView
{
[[_mapView viewWithTag:101] removeFromSuperview];
}

要在触摸 map 中的其他点时关闭弹出 View ,请覆盖此委托(delegate):

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
{
[[_mapView viewWithTag:101] removeFromSuperview];
}

关于iphone - UIPopoverController 在没有委托(delegate)调用的情况下解散,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10341579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com