userLocation と注釈 (plist から) の間の距離を計算しようとしていますが、mapView を実行するたびにシグナル SIGABRT エラーが発生します。
私はmapViewController.mで計算を行っており、計算された値をtableViewControllerに表示したいと考えています。
私のAnnotations.hで
#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>
@interface Annotation : NSObject <MKAnnotation>
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, assign) CLLocationDistance distance;
@property (nonatomic, copy) NSString * title;
@property (nonatomic, copy) NSString * subtitle;
@property (nonatomic, copy) NSString * sculptureIdKey;
@end
私は距離を合成しています = _distance; 私のAnnotations.mファイルで。
私のmapViewController.mで計算を行っています
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
for (Annotation *annotation in self.mapView.annotations)
{
CLLocationCoordinate2D coord = [annotation coordinate];
CLLocation *annLocation = [[CLLocation alloc] initWithLatitude:coord.latitude longitude:coord.longitude];
annotation.distance = [annLocation distanceFromLocation:newLocation];
CLLocationDistance calculatedDistance = [annLocation distanceFromLocation:newLocation];
annotation.distance = calculatedDistance;
NSLog(@"Calculated Distance:%.2f m\n", calculatedDistance);
}
}
そして私のtableViewController.hで
#import "mainViewController.h"
#import "mapViewController.h"
#import "Annotation.h"
@interface ListViewController : UITableViewController <UITableViewDataSource, UITableViewDelegate, CLLocationManagerDelegate>
@property (readonly) CLLocationCoordinate2D selectedCoordinate;
@property (nonatomic, assign) CLLocationDistance distance;
@property (nonatomic, strong) CLLocationManager *locationManager;
@property (nonatomic, strong) CLLocation *userLocation;
@property (nonatomic, strong) NSArray *locationsArray;
@end
そしてtableViewController.m
#import "ListViewController.h"
#import "customCell.h"
@interface ListViewController ()
@end
@implementation ListViewController
@synthesize locationsArray = _locationsArray;
@synthesize locationManager = _locationManager;
@synthesize selectedCoordinate = _selectedCoordinate;
@synthesize distance = _distance;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.locationsArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
customCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (!cell)
{
cell = [[customCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.customTitle.text = [[self.locationsArray objectAtIndex:indexPath.row] valueForKey:@"sculptureNameKey"];
cell.customSubTitle.text = [[self.locationsArray objectAtIndex:indexPath.row] valueForKey:@"sculptureAddressKey"];
cell.distanceLabel.text = [NSString stringWithFormat:@"Nice distance:%f m\n", _distance];
return cell;
}
ログの私の出力は次のとおりです
2013-02-15 11:05:50.769 TalkingSculpture[11639:c07] Calculated Distance:83971.36 m
2013-02-15 11:05:50.770 TalkingSculpture[11639:c07] Calculated Distance:83406.16 m
2013-02-15 11:05:50.771 TalkingSculpture[11639:c07] Calculated Distance:86002.30 m
2013-02-15 11:05:50.771 TalkingSculpture[11639:c07] -[MKUserLocation setDistance:]: unrecognized selector sent to instance 0xee4f080
2013-02-15 11:05:50.772 TalkingSculpture[11639:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MKUserLocation setDistance:]: unrecognized selector sent to instance 0xee4f080'
*** First throw call stack:
(0x1b44012 0x1460e7e 0x1bcf4bd 0x1b33bbc 0x1b3394e 0x3ef8 0x3637e 0x3593f 0x339c5 0x2f175 0x1b03920 0x1ac6d31 0x1aeac51 0x1ae9f44 0x1ae9e1b 0x1a9e7e3 0x1a9e668 0x3a4ffc 0x43ed 0x2535)
libc++abi.dylib: terminate called throwing an exception