Objective c 从MySQL数据库中提取MapView注释的坐标,但注释不是';你不来吗?

Objective c 从MySQL数据库中提取MapView注释的坐标,但注释不是';你不来吗?,objective-c,annotations,mkmapview,sigabrt,Objective C,Annotations,Mkmapview,Sigabrt,我试图从MySQL数据库中提取MapView的坐标,但由于某种原因,我的坐标没有显示在MapView上 见下面我的代码 MapViewController.h文件 #import <UIKit/UIKit.h> #import <MapKit/MapKit.h> @interface MapViewController : UIViewController <MKMapViewDelegate> @property (nonatomic, str

我试图从MySQL数据库中提取MapView的坐标,但由于某种原因,我的坐标没有显示在MapView上

见下面我的代码

MapViewController.h文件

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>    

@interface MapViewController : UIViewController  <MKMapViewDelegate> 
@property (nonatomic, strong) IBOutlet MKMapView *mapView;
@property (nonatomic, retain) NSMutableArray *dispensaries;
@property (nonatomic, retain) NSMutableData *data;
@end
MapViewAnnotation.h

#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>
#import <CoreLocation/CoreLocation.h>

@interface MapViewAnnotation : NSObject <MKAnnotation> {
    CLLocationCoordinate2D coordinate;
    NSString *title;
    NSString *subtitle;
}    
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@end

这似乎是一个问题,因为您希望使用错误的JSON:
服务器输出
包装在一个数组中:

 NSMutableArray *array = [NSMutableArray arrayWithObject:[serverOutput objectFromJSONString]];    

您试图访问一个实际上是数组的JKDictionary(Json工具包字典),因此它不响应objectForKey:

尽量确保:

for (NSDictionary *dictionary in array) {
    assert([dictionary respondsToSelector:@selector(objectForKey:)]);
--

势解 我相信你多余的包装会让事情变得糟糕。尝试:

NSMutableArray *array = [[[serverOutput objectFromJSONString] mutableCopy] autorelease];    

我已经实现了您的解决方案,它阻止了我的应用程序崩溃:)它还显示了我的当前位置,但由于某些原因,它仍然没有在mapview上显示我数据库中的注释。请参阅上面我的更新代码。我们将在addAnnotation调用时停止调试器,并在该点验证数据是否正常。那么,您还没有向我们展示您的类
MapViewAnnotation
,所以这有点猜测:)刚刚在上面发布了我的MapViewAnnotation代码:)我觉得我缺少了一些基本的东西?哈哈,我实现了一个NSLog,以确保数据/JSON正常工作,而且看起来一切正常。但是。。。。(void)viewdiload{[super viewdiload];…很可能是错误的:DSuper-wird,但我重新启动了xCode,您的初始答案才开始工作。哈哈!危机避免了,注释出现了,一切都很神奇:)THX!经过编辑,使代码更紧凑,更易于阅读
for (NSDictionary *dictionary in array) {
    assert([dictionary respondsToSelector:@selector(objectForKey:)]);
NSMutableArray *array = [[[serverOutput objectFromJSONString] mutableCopy] autorelease];