Detect whether UIRefreshControl can be used

  • Hi,

    I am implementing a UIRefreshControl in an app that runs on iOS 5.1 or higher and want to test if the device is running iOS 6, because this is an iOS 6 feature.

    I'd like to avoid detecting the iOS version in runtime and use a respondsToSelector route instead.

    I am getting no compiler error on this codeline, so my first guess is this works, but I'd like to check..

        if ([self respondsToSelector:@selector(setRefreshControl)]) [self setUpRefreshControl];

    Has anybody done this and van they tell me if the above works fine, or, alternatively, how to do this?

    Many thanks!

    diederik
  • On May 8, 2013, at 8:51 AM, Diederik Meijer | Ten Horses <diederik...> wrote:

    > I am implementing a UIRefreshControl in an app that runs on iOS 5.1 or higher and want to test if the device is running iOS 6, because this is an iOS 6 feature.
    >
    > I'd like to avoid detecting the iOS version in runtime and use a respondsToSelector route instead.
    >
    > I am getting no compiler error on this codeline, so my first guess is this works, but I'd like to check..
    >
    > if ([self respondsToSelector:@selector(setRefreshControl)]) [self setUpRefreshControl];
    >
    > Has anybody done this and van they tell me if the above works fine, or, alternatively, how to do this?

    If your intent is to check to see if the UIRefreshControl class exists at runtime, then do this instead:

    if (NSClassFromString(@"UIRefreshControl"))

    The line you wrote above checks to see if the method "setRefreshControl" exists inside the method's own class. I doubt that's your intention, especially since set-methods typically take an argument, and if the method takes an argument, then you would need to use "setRefreshControl:" instead.

    Nick Zitzmann
    <http://www.chronosnet.com/>
  • Thank you Nick, that works perfectly!!

    Op May 8, 2013, om 5:20 PM heeft Nick Zitzmann <nick...> het volgende geschreven:

    >
    > On May 8, 2013, at 8:51 AM, Diederik Meijer | Ten Horses <diederik...> wrote:
    >
    >> I am implementing a UIRefreshControl in an app that runs on iOS 5.1 or higher and want to test if the device is running iOS 6, because this is an iOS 6 feature.
    >>
    >> I'd like to avoid detecting the iOS version in runtime and use a respondsToSelector route instead.
    >>
    >> I am getting no compiler error on this codeline, so my first guess is this works, but I'd like to check..
    >>
    >> if ([self respondsToSelector:@selector(setRefreshControl)]) [self setUpRefreshControl];
    >>
    >> Has anybody done this and van they tell me if the above works fine, or, alternatively, how to do this?
    >
    > If your intent is to check to see if the UIRefreshControl class exists at runtime, then do this instead:
    >
    > if (NSClassFromString(@"UIRefreshControl"))
    >
    > The line you wrote above checks to see if the method "setRefreshControl" exists inside the method's own class. I doubt that's your intention, especially since set-methods typically take an argument, and if the method takes an argument, then you would need to use "setRefreshControl:" instead.
    >
    > Nick Zitzmann
    > <http://www.chronosnet.com/>
    >
    >
previous month may 2013 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today