2012-04-28 102 views
0

你好我們有一個應用程序,我們正在努力,有一些issuse讓註釋正常工作。該應用程序建立和安裝罰款...有大約50k引腳從數據庫上加載的ipad ...IOS 4.3.2 MapKit註釋

問題是,每個引腳將顯示相同的註釋信息時按下...不能圖瞭解如何在按下引腳時引用正確的數據庫字段(引腳全部顯示在正確的位置,因此我們知道它正在引用數據庫)

我想象這是什麼東西嗎?

- (void) loadThePushPinInMap { 
NSString * filename= [[NSBundle mainBundle] pathForResource:@"geocoded" ofType:@"csv"]; 
NSString *data = [NSString stringWithContentsOfFile:filename]; 
NSString *strippedPartOne = [data stringByReplacingOccurrencesOfString:@"\"" withString:@""]; 
NSArray *rows = [strippedPartOne componentsSeparatedByString:@"\r"]; 
int size = [rows count]; 
for (int i =0; i < size; i++) { 
    if(i==0) 
     continue; 
    // This is now the data being parse 
    NSArray * line = [[rows objectAtIndex:i] componentsSeparatedByString:@","]; 


    double lat =[[[line objectAtIndex:5] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] doubleValue]; 
    double lon =[[[line objectAtIndex:6] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] doubleValue]; 

    //MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
    //region.center.latitude = lat ; 
    //region.center.longitude = lon; 
    //region.span.longitudeDelta = 0.01f; 
    //region.span.latitudeDelta = 0.01f; 

    CLLocationCoordinate2D coordinate; 
    coordinate.latitude = lat; 
    coordinate.longitude = lon;   


    MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init]; 
    annotation.coordinate = coordinate; 
    annotation.title = [rows objectAtIndex:0]; 
    annotation.subtitle = [rows objectAtIndex:4]; 

    //[_mapView addAnnotation:annotation]; 
    [self.mapView addAnnotation:annotation]; 

} 

}

這裏是MKAnnotationsview代碼

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

// Post this notification to re-query callout information. 
MK_EXTERN NSString * const MKAnnotationCalloutInfoDidChangeNotification; 

#if (__IPHONE_4_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED) 

enum { 
MKAnnotationViewDragStateNone = 0,  // View is at rest, sitting on the map. 
MKAnnotationViewDragStateStarting,  // View is beginning to drag (e.g. pin lift) 
MKAnnotationViewDragStateDragging,  // View is dragging ("lift" animations are complete) 
MKAnnotationViewDragStateCanceling,  // View was not dragged and should return to it's starting position (e.g. pin drop) 
MKAnnotationViewDragStateEnding   // View was dragged, new coordinate is set and view should return to resting position (e.g. pin drop) 
}; 

typedef NSUInteger MKAnnotationViewDragState; 

#endif // #if (__IPHONE_4_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED) 

@class MKAnnotationViewInternal; 
@protocol MKAnnotation; 

MK_CLASS_AVAILABLE(NA, 3_0) 
@interface MKAnnotationView : UIView 
{ 
@private 
MKAnnotationViewInternal *_internal; 
} 

- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString  *)reuseIdentifier; 

@property (nonatomic, readonly) NSString *reuseIdentifier; 

// Classes that override must call super. 
- (void)prepareForReuse; 

@property (nonatomic, retain) id <MKAnnotation> annotation; 

@property (nonatomic, retain) UIImage *image; 

// By default, the center of annotation view is placed over the coordinate of the annotation. 
// centerOffset is the offset in screen points from the center of the annotion view. 
@property (nonatomic) CGPoint centerOffset; 

// calloutOffset is the offset in screen points from the top-middle of the annotation view, where the anchor of the callout should be shown. 
@property (nonatomic) CGPoint calloutOffset; 

// Defaults to YES. If NO, ignores touch events and subclasses may draw differently. 
@property (nonatomic, getter=isEnabled) BOOL enabled; 

// Defaults to NO. This gets set/cleared automatically when touch enters/exits during tracking and cleared on up. 
@property (nonatomic, getter=isHighlighted) BOOL highlighted; 

// Defaults to NO. Becomes YES when tapped on in the map view. 
@property (nonatomic, getter=isSelected) BOOL selected; 
- (void)setSelected:(BOOL)selected animated:(BOOL)animated; 

// If YES, a standard callout bubble will be shown when the annotation is selected. 
// The annotation must have a title for the callout to be shown. 
@property (nonatomic) BOOL canShowCallout; 

// The left accessory view to be used in the standard callout. 
@property (retain, nonatomic) UIView *leftCalloutAccessoryView; 

// The right accessory view to be used in the standard callout. 
@property (retain, nonatomic) UIView *rightCalloutAccessoryView; 

// If YES and the underlying id<MKAnnotation> responds to setCoordinate:, 
// the user will be able to drag this annotation view around the map. 
@property (nonatomic, getter=isDraggable) BOOL draggable NS_AVAILABLE(NA, 4_0); 

// Automatically set to MKAnnotationViewDragStateStarting, Canceling, and Ending when necessary. 
// Implementer is responsible for transitioning to Dragging and None states as appropriate. 
@property (nonatomic) MKAnnotationViewDragState dragState NS_AVAILABLE(NA, 4_0); 

// Developers targeting iOS 4.2 and after must use setDragState:animated: instead of setDragState:. 
- (void)setDragState:(MKAnnotationViewDragState)newDragState animated:(BOOL)animated NS_AVAILABLE(NA, 4_2); 


@end 

這裏是Delegate.h碼.....

#import "MapinAppDelegate.h" 

@implementation MapinAppDelegate 

@synthesize window = _window; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
// Override point for customization after application launch. 
return YES; 
} 

- (void)applicationWillResignActive:(UIApplication *)application 
{ 
/* 
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 
*/ 
} 

- (void)applicationDidEnterBackground:(UIApplication *)application 
{ 
/* 
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
*/ 
} 

- (void)applicationWillEnterForeground:(UIApplication *)application 
{ 
/* 
Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 
*/ 
} 

- (void)applicationDidBecomeActive:(UIApplication *)application 
{ 
/* 
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
*/ 
} 

- (void)applicationWillTerminate:(UIApplication *)application 
{ 
/* 
Called when the application is about to terminate. 
Save data if appropriate. 
See also applicationDidEnterBackground:. 
*/ 

}

@end

這裏有Delegate.m代碼....

#import <UIKit/UIKit.h> 

@interface MapinAppDelegate : UIResponder <UIApplicationDelegate> 

@property (strong, nonatomic) UIWindow *window; 

@end 
+0

的問題可能是你'viewForAnnotation:'委託方法,其中創建實際的看法。 – 2012-04-28 13:49:24

+0

您是否正確設置了註釋視圖的註記屬性? 你能否提供你的'viewForAnnotation:'代碼? – yinkou 2012-04-28 14:21:34

+0

在上面添加了viewForAnnotation的代碼 – Monergy 2012-04-28 16:46:01

回答

0

使用由MKAnnotation繼承只,在該類指定自己的屬性,如locationDetails,locationImage等

要CustomAnnotaion添加此信息,更新MKAnnotatinView,通過實施該委託 - (MKAnnotationView *)的MapView:(*的MKMapView)的MapView viewForAnnotation:(ID)註釋

例子: http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html

http://www.highoncoding.com/Articles/805_Consuming_XML_Feed_and_Displaying_Public_Information_on_the_MapView_Control.aspx

+0

我只是試圖添加上面提到的委託,但我得到一個彈出窗口說明MKAnnotationView被鎖定?我厭倦瞭解鎖它來做出這些改變,但它是說我不「擁有」它,所以我不允許改變它? – Monergy 2012-04-28 21:25:09