【发布时间】:2010-04-14 16:57:27
【问题描述】:
我有一个带有注释的 MKMapView(也是一个 UIPopoverControllerDelegate)。此 MapView 在 MKTestMapView.h 文件中具有在 @interface 中定义的 UIPopoverController* popoverController 和在 @interface 部分之外定义的 @property (nonatomic, retain) UIPopoverController* popoverController;。这个控制器是 MKTestMapView.m 文件中的@synthesized,它在- (void)dealloc 部分中发布。此 MapView 中的注释已将 rightCalloutAccessoryViews 定义为以下内容:
- (void)mapView:(MKMapView *)mapView2 annotationView:(MKAnnotationView *)aview calloutAccessoryControlTapped:(UIControl *)control{
...
CGPoint leftTopPoint = [mapView2 convertCoordinate:aview.annotation.coordinate toPointToView:mapView2];
int boxDY=leftTopPoint.y;
int boxDX=leftTopPoint.x;
NSLog(@"\nDX:%d,DY:%d\n",boxDX,boxDY);
popoverController = [[UIPopoverController alloc] initWithContentViewController:controller];
popoverController.delegate = self;
CGSize maximumLabelSize = CGSizeMake(320.0f,600.0f);
popoverController.popoverContentSize = maximumLabelSize;
CGRect rect = CGRectMake(boxDX, boxDY, 320.0f, 600.0f);
[popoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
...
}
现在有趣的部分来了。首先,我不确定我是否需要 maximumLabelSize 和 rect 大小相同。我是 popovercontroller 的新手,所以我是靠耳朵玩的..
好的,弹出窗口显示。现在解雇它。我可以单击 mapView2 上的任何位置,弹出框消失...但是如果用户更改任何内容,我需要用户单击视图中的按钮。啊!
文档显示:
要以编程方式关闭弹出框, 调用dismissPopoverAnimated: popover 控制器的方法。
好吧,问题来了:根据 popoverController 工作方式的定义,您在显示的弹出框的视图内部单击(单击按钮)但必须触发 dismissPopoverAnimated: 方法启动这个弹出视图的控制器,在我的例子中,是 MKTestMapView.m 文件中的popoverController。
现在,说了这么多,记住,[popoverController release] 直到:
- (void)dealloc {
[popoverController release];
[mapView release];
[super dealloc];
}
那么,我是否只是在按钮内执行以下操作(混乱但可能有效):
(假设我的弹出视图是一个 TableView)在:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MKTestMapView * mKTestMapView = [[MKTestMapView alloc] init];
[[mKTestMapView popoverController].dismissPopoverAnimated:YES];
}
这是我的问题:我不知道执行上述操作是否会给我一个reference(如果有的话)屏幕上的现有视图 - 因此作为该 popoverController 所有者的视图。如果它像
[[[self parentView] popoverController].dismissPopoverAnimated:YES];
我会开枪的,因为我也不认为这是正确的语法!
这应该很容易......但我迷路了。 (可能只是对我正在学习的 iPad 差异如此之多感到沮丧)。
谁能解释一下?
【问题讨论】:
标签: iphone ipad mkmapview uipopovercontroller