0

I try like this, but it isn't work. How can i do this ?

MKAnnotationView *pointTest = [[MKAnnotationView alloc] init];
    pointTest.annotation = point;
    pointTest.draggable= YES;

    UITextField *pointText = [[UITextField alloc] initWithFrame:CGRectMake(location.latitude, location.longitude, 100, 20)];
    pointText.backgroundColor = [UIColor blackColor];
    pointTest.rightCalloutAccessoryView = pointText;
    pointTest.canShowCallout = YES;
    [self.userMap addAnnotation:pointTest];
Senthil
  • 510
  • 12
  • 28
bguler
  • 237
  • 1
  • 5
  • 11
  • This code doesn't make sense. It's passing pointTest which is an MKAnnotationView to addAnnotation which expects an object of type id. An MKAnnotationView is supposed to be created in the viewForAnnotation delegate method which the map view calls _after_ you've called addAnnotation. Generally, only small buttons and images can be used as accessory views. And as already pointed out, latitude and longitude are not screen coordinates. Please read the docs and guides on developer.apple.com or some 3rd-party tutorial first. –  Nov 06 '13 at 00:13

1 Answers1

1

First of all, you are setting a wrong frame for the pointText UITextField, latitude and longitude are not screen coordinates, it should be implemented like this:

CGFloat originX = 0; //Or other value
CGFLoat originY = 0; //Or other value
UITextField *pointText = [[UITextField alloc] initWithFrame:CGRectMake(originX, originY, 100, 20)];

You may also need to set canShowCallout to YES:

pointTest.canShowCallout = YES;

Then, you are setting the rightCalloutAccessoryView as an UITextField, which is not the best thing to do. A common view to specify for this property is UIButton object whose type is set to UIButtonTypeDetailDisclosure. For titles and subtitles, I prefer using the annotation attribute:

point.title = "Your title";
pointTest.annotation = point;

You should check the apple documentation.

Brams
  • 584
  • 4
  • 9