Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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
Ios 实现MKAnnotation协议时发生SIGABRT错误_Ios_Objective C_Mkannotation_Sigabrt - Fatal编程技术网

Ios 实现MKAnnotation协议时发生SIGABRT错误

Ios 实现MKAnnotation协议时发生SIGABRT错误,ios,objective-c,mkannotation,sigabrt,Ios,Objective C,Mkannotation,Sigabrt,我一直在尝试使用MKMapView做一个简单的应用程序,在尝试调用类时,我遇到了一个SIGABRT错误 DetailViewController.m文件: #import "WVTDetailViewController.h" #import <MapKit/MapKit.h> #import <AddressBook/AddressBook.h> #import "Pin.h" @interface WVTDetailViewController () { C

我一直在尝试使用MKMapView做一个简单的应用程序,在尝试调用
类时,我遇到了一个SIGABRT错误

DetailViewController.m
文件:

#import "WVTDetailViewController.h"
#import <MapKit/MapKit.h>
#import <AddressBook/AddressBook.h>
#import "Pin.h"

@interface WVTDetailViewController ()
{
    CLLocationCoordinate2D location;
    NSMutableDictionary *masterDict;
    NSDictionary *googleDict;
    NSDictionary *yahooDict;
    NSDictionary *appleDict;
    NSDictionary *microsoftDict;
    NSDictionary *facebookDict;
}

- (void)configureView;
@end

@implementation WVTDetailViewController

@synthesize address = _address;

- (void)configureView
{
    // Update the user interface for the detail item.

}

- (void)viewDidLoad
{
   [super viewDidLoad];
   // Do any additional setup after loading the view, typically from a nib.
   [self configureView];
   [_mapView setShowsUserLocation:YES];

   CLLocationCoordinate2D googleLocation;
   googleLocation.latitude = 37.4221;
   googleLocation.longitude = -122.0844;

   // Yahoo:
   CLLocationCoordinate2D yahooLocation;
   yahooLocation.latitude = 37.417354;
   yahooLocation.longitude = -122.025189;

   // Apple:
   CLLocationCoordinate2D appleLocation;
   appleLocation.latitude = 37.332313;
   appleLocation.longitude = -122.030746;

   // Microsoft:
   CLLocationCoordinate2D microsoftLocation;
   microsoftLocation.latitude = 47.639764;
   microsoftLocation.longitude = -122.128435;

   // Facebook:
   CLLocationCoordinate2D facebookLocation;
   facebookLocation.latitude = 37.483489;
   facebookLocation.longitude = -122.149542;

   if ([_address isEqualToString:@"Google"])
   {
      location = googleLocation;
   }
   if ([_address isEqualToString:@"Yahoo"])
   {
      location = yahooLocation;
   }
   if ([_address isEqualToString:@"Apple"])
   {
      location = appleLocation;
   }
   if ([_address isEqualToString:@"Microsoft"])
   {
      location = microsoftLocation;
   }
   if ([_address isEqualToString:@"Facebook"])
   {
      location = facebookLocation;
   }

googleDict =     @{(NSString *)kABPersonAddressStreetKey: @"1600 Amphitheatre Pkwy",
                   (NSString *)kABPersonAddressCityKey: @"Mountain View",
                   (NSString *)kABPersonAddressStateKey: @"CA",
                   (NSString *)kABPersonAddressZIPKey: @"94043"
                  };

yahooDict =      @{(NSString *)kABPersonAddressStreetKey: @"701 1st Ave",
                   (NSString *)kABPersonAddressCityKey: @"Sunnyvale",
                   (NSString *)kABPersonAddressStateKey: @"CA",
                   (NSString *)kABPersonAddressZIPKey: @"94089"
                   };

appleDict =      @{(NSString *)kABPersonAddressStreetKey: @"1 Infinite Loop",
                   (NSString *)kABPersonAddressCityKey: @"Cupertino",
                   (NSString *)kABPersonAddressStateKey: @"CA",
                   (NSString *)kABPersonAddressZIPKey: @"95014"
                   };

microsoftDict =  @{(NSString *)kABPersonAddressStreetKey: @"One Microsoft Way",
                   (NSString *)kABPersonAddressCityKey: @"Redmond",
                   (NSString *)kABPersonAddressStateKey: @"WA",
                   (NSString *)kABPersonAddressZIPKey: @"98052"
                   };

facebookDict =   @{(NSString *)kABPersonAddressStreetKey: @"1 Hacker Way",
                   (NSString *)kABPersonAddressCityKey: @"Menlo Park",
                   (NSString *)kABPersonAddressStateKey: @"CA",
                   (NSString *)kABPersonAddressZIPKey: @"94025"
                   };

    masterDict = [[NSMutableDictionary alloc] init];

    [masterDict setObject: googleDict forKey: @"Google"];
    [masterDict setObject: yahooDict forKey: @"Yahoo"];
    [masterDict setObject: appleDict forKey: @"Apple"];
    [masterDict setObject: microsoftDict forKey: @"Microsoft"];
    [masterDict setObject: facebookDict forKey: @"Facebook"];
}

- (void)viewWillAppear:(BOOL)animated
{
    // Establish a 1.5km "square" around the 2D coordinate "location" and display it
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(location, 1500, 1500);
    [_mapView setRegion:viewRegion animated:YES];

    Pin *myLocationPin = [[Pin alloc] initWithNameAndCoords: _address coords: location];
    myLocationPin.addr = [masterDict objectForKey:_address];
    [_mapView addAnnotation: myLocationPin];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
首先,SIGABRT错误位于
[\u mapView addAnnotation:myLocationPin]行。我还在
Pin.m
中收到一条警告,说
自动属性合成不会合成协议中声明的属性
。我使用
@synthesis
指令强制合成


不过,我已经查看了调试器的输出,这似乎不是问题——合成的属性正在接收它们应该接收的值。

您应该将其添加到Pin.m中的getter函数中

-(CLLocationCoordinate2D)coordinate { return _coord; }

让我们也来看看pin.h,P.S.永远不要忽视警告,也不要试图强迫他们安静下来。99%的时候没有火就没有烟。
-(CLLocationCoordinate2D)coordinate { return _coord; }