我正在开发一个带注释的基于地图的应用程序。我希望将注释标注中的附件按钮连接到segue到详细视图控制器。
我在故事板中添加了一个新的视图控制器,其中包含来自地图视图的视图控制器的推送segue,其标识为firePit
我的ViewController.m
如下
#import“ViewController.h”
#import“Annotations.h”
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
_mapView.showsUserLocation = YES;
_mapView.delegate = self;
//Setting the Visable Region
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(45.036179, -87.134691);
MKCoordinateRegion adjustedRegion = [_mapView regionThatFits:MKCoordinateRegionMakeWithDistance(center, 2000, 1900)];
[self.mapView setRegion: adjustedRegion animated:YES];
//Annotations - Is this the best place?
CLLocationCoordinate2D firePitCoord = CLLocationCoordinate2DMake( 45.037559, -87.130526);
Annotations *firePit = [[Annotations alloc] initWithTitle:@"Fire Pit" Location:firePitCoord];
[self.mapView addAnnotation:firePit];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString *identifier = @"Fire Pit";
if ([annotation isKindOfClass:[Annotations class]]) {
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
} else {
annotationView.annotation = annotation;
}
return annotationView;
}
return nil;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
[self performSegueWithIdentifier:@"firePit" sender:view]; //thread breakdown 3.1
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(MKAnnotationView *)sender
{
if ([segue.identifier isEqualToString:@"firePit"])
{
MKAnnotationView *annotationView = sender;
[segue.destinationViewController setAnnotation:annotationView.annotation];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
应用程序在模拟器中起作用,直到我按下注释标注中的附件按钮。然后崩溃并警告我[self performSegueWithIdentifier:@"firePit" sender:view]
方法中的线程细分(如代码中所述)。
如果有人能够提供对此问题的深入了解,我将非常感激。我似乎无法从任何其他资源中寻求帮助,但如果您有推荐我会喜欢链接。
谢谢