Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3485374
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:53:59+00:00 2026-05-18T10:53:59+00:00

Before iOS 4, I used to add a observer to each MKAnnotationView added to

  • 0

Before iOS 4, I used to add a observer to each MKAnnotationView added to the map view, listening for it’s selected method, so I know when the user has tapped on a pin.

This worked fine up to iOS 4.2. I’ve noticed on the release noted annotation views are actually being reused and it somehow messes up with the observers.

So I figure I can use the -mapview:didSelectAnnotationView: method from MKMapViewDelegate for my needs, but that has only been added to iOS 4.0 SDK.

So, to maintain compatibility, I’d like to implement this method on my delegate and conditionally check for the presence of this method on the MKMapViewDelegate protocol so that if it’s not present, I will add my observer to the annotation view.

How can I do this for a protocol method, similarly for how we check if a class is not nil?

UPDATE:

As Daniel Dickison pointed out, I can’t use respondsToSelector:, because my delegate has -mapview:didSelectAnnotationView: implemented for 4.0+ devices. What I need is to check if the protocol on that device has the optional -mapview:didSelectAnnotationView: method OR if MKMapView will look for that method on it’s delegate.

I ended up doing a test for the current iOS version running. If it’s higher than 4.0, MKMapView will look for that method and call it.

if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 4.0)
    [self setupObserver];

This solves the original problem, but it would still be interesting to check the actual protocol for the method somehow.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:54:00+00:00Added an answer on May 18, 2026 at 10:54 am

    That’s a tricky one. So if I’m understanding your question correctly, you want to find out, at runtime, whether the map view sends the mapView:didSelectAnnotationView: message to its delegate. But you can’t use conformsToProtocol: or respondsToSelector: because you’re implementing the delegate so obviously you’re adopting the protocol and implementing the method.

    The only thing I can think of is to check for some other method that was added to MKMapView (not the delegate) in iOS 4, like: mapRectThatFits:.

    Another possibility is to use the Objective-C runtime library to query the Protocol object. But this is probably overkill, and also I don’t think it will work because the Protocol object is created by the compiler when you build your app, and it’s possible you’ll get the UIKit SDK-defined MKMapViewDelegate protocol object instead of whatever the runtime was compiled with.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before I upgraded to Firefox 3 I used to constantly use the View Source
I know a lot of iOS conversion questions have been asked before but I
Before I start, I know there is this post and it doesn't answer my
Before moving on to use SVN, I used to manage my project by simply
I am running iOS 4 on a jailbroken iPhone 3GS. Before I upgraded to
I'm diving into iOS development and am getting familiar with navigation view controllers. I'm
My PM wants me to include support for older iOS versions before going to
I been listening around that facebook iOS sdk is not functioning properly. Is there
UIView creates a window graphics context before a custom drawRect: method is invoked, so
As described in the README for facebook-ios-sdk, my app calls Facebook#authorize:delegate: before performing any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.