Reputation: 5332
I'm getting a wee bit cross, here.
As far as I know, I am doing everything correctly.
I am doing what it says in this posting, but no dice.
The basic issue is that the draggable marker will not drag.
Here is the trouble spot. I want to specialize a simple black marker (the base class is a non-draggable black marker) to be draggable.
Here is its interface:
/**************************************************************//**
\class BMLT_Search_BlackAnnotationView
\brief We modify the black annotation view to allow dragging.
*****************************************************************/
@interface BMLT_Search_BlackAnnotationView : BMLT_Results_BlackAnnotationView
@property (nonatomic,readwrite,assign) CLLocationCoordinate2D coordinate;
- (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier coordinate:(CLLocationCoordinate2D)inCoordinate;
@end
And here is its implementation:
/**************************************************************//**
\class BMLT_Search_BlackAnnotationView
\brief We modify the black annotation view to allow dragging.
*****************************************************************/
@implementation BMLT_Search_BlackAnnotationView
@synthesize coordinate;
/**************************************************************//**
\brief We simply switch on the draggable bit, here.
\returns self
*****************************************************************/
- (id)initWithAnnotation:(id<MKAnnotation>)annotation
reuseIdentifier:(NSString *)reuseIdentifier
coordinate:(CLLocationCoordinate2D)inCoordinate
{
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
if ( self )
{
[self setDraggable:YES];
[self setCoordinate:inCoordinate];
}
return self;
}
/**************************************************************//**
\brief Handles dragging.
*****************************************************************/
- (void)setDragState:(MKAnnotationViewDragState)newDragState
animated:(BOOL)animated
{
#ifdef DEBUG
NSLog(@"BMLT_Search_BlackAnnotationView setDragState called with a drag state of %@.", newDragState);
#endif
self.dragState = newDragState;
}
@end
setDragState: animated: never gets called.
As far as I know, I am doing everything right.
Obviously, I am not.
Any ideas?
Here is the setup and callback:
/**************************************************************//**
\brief If this is an iPad, we'll set up the map.
*****************************************************************/
- (void)setUpMap
{
if ( mapSearchView ) // This will be set in the storyboard.
{
#ifdef DEBUG
NSLog(@"A_BMLT_SearchViewController setUpIpadMap called (We're an iPad, baby!).");
#endif
BMLTAppDelegate *myAppDelegate = [BMLTAppDelegate getBMLTAppDelegate]; // Get the app delegate SINGLETON
CLLocationCoordinate2D center;
#ifdef DEBUG
NSLog(@"A_BMLT_SearchViewController setUpIpadMap We're using the canned coordinates.");
#endif
center.latitude = [NSLocalizedString(@"INITIAL-MAP-LAT", nil) doubleValue];
center.longitude = [NSLocalizedString(@"INITIAL-MAP-LONG", nil) doubleValue];
if ( [myAppDelegate myLocation] )
{
#ifdef DEBUG
NSLog(@"A_BMLT_SearchViewController setUpIpadMap We know where we are, so we'll set the map to that.");
#endif
center = [myAppDelegate myLocation].coordinate;
}
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(center, 25000, 25000);
[mapSearchView setRegion:region animated:NO];
BMLT_Results_MapPointAnnotation *myMarker = [[BMLT_Results_MapPointAnnotation alloc] initWithCoordinate:center andMeetings:nil];
[myMarker setTitle:@"Marker"];
[mapSearchView addAnnotation:myMarker];
if ( [[BMLT_Prefs getBMLT_Prefs] keepUpdatingLocation] ) // If the user wants us to keep track of them, then we'll do so.
{
[mapSearchView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
}
else
{
[mapSearchView setUserTrackingMode:MKUserTrackingModeNone animated:NO];
}
}
}
#pragma mark - MkMapAnnotationDelegate Functions -
/**************************************************************//**
\brief Returns the view for the marker in the center of the map.
\returns an annotation view, representing the marker.
*****************************************************************/
- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id < MKAnnotation >)annotation
{
#ifdef DEBUG
NSLog(@"A_BMLT_SearchViewController viewForAnnotation called.");
#endif
static NSString* identifier = @"single_meeting_annotation";
MKAnnotationView* ret = [mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if ( !ret )
{
ret = [[BMLT_Search_BlackAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier coordinate:[annotation coordinate]];
}
return ret;
}
Upvotes: 0
Views: 627
Reputation: 5332
Just wanted to report on the REAL problem here:
PEBCAK
The issue is that the drag target on the icon is teeny-tiny. With the simulator, the manipulator (the cursor) is also teeny-tiny, so it can be a challenge to line 'em up.
It's better on the device, with my finger, although that, too, is twitchy.
BTW: The code for the map is different from the above by now. I fixed a few other issues.
If anyone wants to see the code, the entire project is open-source (GitHub -Look up BMLT IOS). I'm currently working in the 2.0 branch, and will be for a while, so it's a moving target.
Upvotes: 0
Reputation: 1400
You need to set your anootation View to be draggable.
[ret setDraggable:YES]
Upvotes: 1