我有一个带有注释的 MKMapView(也是一个 UIPopoverControllerDelegate)。此 MapView 在MKTestMapView.h文件中具有UIPopoverController* popoverController
在 @interface 中@property (nonatomic, retain) UIPopoverController* popoverController;
定义的和在该部分之外定义的@interface
。此控制器@synthesized
位于MKTestMapView.m文件中,并在该- (void)dealloc
部分中发布。此 MapView 中的注释已rightCalloutAccessoryView
定义为以下内容:
- (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: 方法。
好吧,问题来了:根据 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 差异感到沮丧)。
谁能解释更多?