Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何使MKMapKit中注释中的详图索引按钮转到其他视图控制器_Iphone_Objective C_Mkmapview_Mapkit - Fatal编程技术网

Iphone 如何使MKMapKit中注释中的详图索引按钮转到其他视图控制器

Iphone 如何使MKMapKit中注释中的详图索引按钮转到其他视图控制器,iphone,objective-c,mkmapview,mapkit,Iphone,Objective C,Mkmapview,Mapkit,我希望详图索引中的按钮转到另一个视图控制器以显示额外信息,然后能够返回到地图视图。地图位于选项卡式视图控制器的内部。目前,如果您单击标注中的按钮,应用程序将崩溃,并给您一个线程错误。不知道现在该做什么 这是头文件: #import UIKit/UIKit.h> #import MapKit/MapKit.h> #define METERS_PER_MILE 1609.344 @interface MSKSecondViewController :UIViewController&l

我希望详图索引中的按钮转到另一个视图控制器以显示额外信息,然后能够返回到地图视图。地图位于选项卡式视图控制器的内部。目前,如果您单击标注中的按钮,应用程序将崩溃,并给您一个线程错误。不知道现在该做什么

这是头文件:

#import UIKit/UIKit.h>
#import MapKit/MapKit.h>
#define METERS_PER_MILE 1609.344

@interface MSKSecondViewController :UIViewController<MKMapViewDelegate>
{
    IBOutlet MKMapView *stillwellMapView;
}
@property (nonatomic, assign) CLLocationCoordinate2D mainEntranceToStillwellCoordinate;
@end
#导入UIKit/UIKit.h>
#导入MapKit/MapKit.h>
#定义每英里的米数1609.344
@接口MSKSecondViewController:UIViewController
{
iBMAppView*stillwellMapView;
}
@属性(非原子,赋值)CLLocationCoordinate2D主入口至TillwellCoordinate;
@结束
这是实施文件:

@interface MSKSecondViewController ()
@end
@implementation MSKSecondViewController
@synthesize mainEntranceToStillwellCoordinate;

- (void)viewDidLoad
{
    [super viewDidLoad];
    stillwellMapView.delegate=self;
    // Do any additional setup after loading the view, typically from a nib.
    [self mainEntrancetoStillwellCoordinate];
    [self bambooForestCoordinate];
}

- (void)mainEntrancetoStillwellCoordinate
{
    MKPointAnnotation * main = [[MKPointAnnotation alloc]init];
    CLLocationCoordinate2D mainLocation;
    mainLocation.latitude = 40.831685;
    mainLocation.longitude = -73.477453;
    [main setCoordinate:mainLocation];
    [main setTitle:@"Entrance"];
    [main setSubtitle:@"Main"];
    [stillwellMapView addAnnotation:main];
}
- (void)bambooForestCoordinate
{
    MKPointAnnotation * bambooForest = [[MKPointAnnotation alloc]init];
    CLLocationCoordinate2D bambooForestLocation;
    bambooForestLocation.latitude = 40.829118;
    bambooForestLocation.longitude = -73.466443;
    [bambooForest setCoordinate:bambooForestLocation];
    [bambooForest setTitle:@"Bamboo Forest"];
    [bambooForest setSubtitle:@"Exit to Woodbury"];
    [stillwellMapView addAnnotation:bambooForest];
}

- (void)viewDidUnload
{
    stillwellMapView = nil;
    [super viewDidUnload]; 
    // Release any retained subviews of the main view.
}
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation: 
(id<MKAnnotation>)annotation    
{
    MKPinAnnotationView * annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
    UIButton *entranceButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [entranceButton addTarget:self action:@selector(entranceButtonPressed:) 
forControlEvents:UIControlEventTouchUpInside];
    annView.rightCalloutAccessoryView = entranceButton;
    entranceButton = [UIButton buttonWithType:UIButtonTypeCustom];
    entranceButton.frame = CGRectMake(0, 0, 23, 23);
    entranceButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    entranceButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [UIButton buttonWithType:UIButtonTypeDetailDisclosure];  
    annView.animatesDrop=TRUE;
    annView.canShowCallout = YES;
    annView.calloutOffset = CGPointMake(-5, 5);
    return annView;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)viewWillAppear:(BOOL)animated 
{  
    //the coordinates in which the map shows once loaded
    CLLocationCoordinate2D zoomLocation;
    zoomLocation.latitude = 40.831922;
    zoomLocation.longitude= -73.476353; 
    //the amount of area shown by the map when it loads
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation,  
0.15*METERS_PER_MILE, 0.15*METERS_PER_MILE); 
    MKCoordinateRegion adjustedRegion = [stillwellMapView regionThatFits:viewRegion];                
    [stillwellMapView setRegion:adjustedRegion animated:YES]; 
}
@end
@接口MSKSecondViewController()
@结束
@MSKSecondViewController的实现
@综合主井坐标;
-(无效)viewDidLoad
{
[超级视图下载];
stillwellMapView.delegate=self;
//加载视图后,通常从nib执行任何其他设置。
[自我维护和自我协调];
[自竹];
}
-(无效)主入口至井坐标
{
MKPointAnnotation*main=[[MKPointAnnotation alloc]init];
CLLOCATIONCoordination2D主位置;
mainLocation.latitude=40.831685;
mainLocation.longitude=-73.477453;
[主设置坐标:主位置];
[主要片名:@“入口”];
[主要设置子标题:@“主要”];
[stillwellMapView addAnnotation:main];
}
-(空)竹林
{
MKPointAnnotation*bamboofreest=[[MKPointAnnotation alloc]init];
位置协调2 d竹林位置;
竹林位置纬度=40.829118;
竹林位置。经度=-73.466443;
[竹林设置坐标:竹林位置];
[竹林集名:@“竹林”];
[Bamboofreest setSubtitle:@“伍德伯里出口”];
[stillwellMapView addAnnotation:bambooForest];
}
-(无效)视图卸载
{
stillwellMapView=零;
[超级视频下载];
//释放主视图的所有保留子视图。
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:
(id)注释
{
MKPinAnnotationView*annView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:nil];
UIButton*EnterButton=[UIButton Button类型:UIButtonTypedTailButton];
[入口按钮添加目标:自我操作:@选择器(入口按钮按下:)
forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView=入口按钮;
入口按钮=[UIButton按钮类型:UIButtonTypeCustom];
enterButton.frame=CGRectMake(0,0,23,23);
入口按钮。内容垂直对齐=uicontrol内容垂直对齐中心;
EnterButton.contentHorizontalAlignment=uicontrol内容HorizontalAlignment中心;
[UIButton按钮类型:UIButtonTypedTailExposure];
annView.animatesDrop=TRUE;
annView.canShowCallout=是;
annView.calloutOffset=CGPointMake(-5,5);
返回视图;
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation
{
返回(interfaceOrientation!=UIInterfaceOrientation肖像向上向下);
}
-(无效)视图将显示:(BOOL)动画
{  
//地图加载后显示的坐标
C定位协调2 D动物定位;
zoomLocation.latitude=40.831922;
动物位置经度=-73.476353;
//地图加载时显示的面积大小
MKCoordinateRegion viewRegion=MKCoordinateRegionMakeWithDistance(缩放位置,
每英里0.15*米,每英里0.15*米);
MKCoordinateRegion adjustedRegion=[stillwellMapView RegionAtfits:viewRegion];
[stillwellMapView设置区域:调整区域动画:是];
}
@结束

使用“进入”按钮添加您已在内部修补中注册的事件

-(void) entranceButtonPressed:(UIButton *)sender
{
//Write the controller push code here
}

此外,在代码中,一旦将入口按钮指定给rightCalloutAccessoryView,则必须重新初始化该按钮

在mapView:viewForAnnotation:delegate方法中

-(MKAnnotationView *)mapView:(MKMapView *)mapView
        viewForAnnotation:(id <MKAnnotation>)annotation 
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
然后在下面的委托方法中实现导航到其他视图控制器的代码

-(MKAnnotationView *)mapView:(MKMapView *)mapView
        viewForAnnotation:(id <MKAnnotation>)annotation 
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control

确保视图控制器嵌入到导航控制器中

这行“[UIButton Button WithType:UIButtonTypedTailExposition];”您想做什么?被制作并返回给你的按钮只是被放弃了。这条线对你的生活没有影响app@Craig,没有这一行,应用程序就无法运行。如果你把它注释掉,你会得到一个错误,说enterButton不是declaredNo不是那一行,那一行再往下一点,以[UIButton buttonwi……。你在“enterButton=”上正确地使用了它line.buttonWithType向您返回一个按钮,但由于您没有将其保存在该行中,该按钮会被丢弃。@Craig,所以我去掉了该行,现在当您单击该按钮时,该应用程序不会崩溃。它实际上什么都不做。我如何才能让它显示更多信息,比如在另一个视图控制器中。我必须这样做吗创建自定义类?首先,如果有帮助,请投票支持我的评论。接下来按照Apurv所说的做。addTarget函数设置当你按下按钮时将调用的函数,但是如果你已经编写了该函数,你希望你的应用程序做什么?如果有帮助,请接受Apurv的答案。我们大多数人不会重新初始化它。一次就足够了,你可以在该函数的第二行执行此操作。