简体   繁体   中英

Warning Received When Using Reachability

I'm having a problem with Apple's Reachability class. I use it successfully from the AppDelate, but when I try to use it from another view controller class I get the warning below, though it still works. Any help is appreciated. lq

//  MyViewController.m

#import "Reachability.h"

- (void) viewDidLoad {

    [[NSNotificationCenter defaultCenter] addObserver: self 
        selector: @selector(reachabilityChangedState:) 
        name: kReachabilityChangedNotification 
        object: nil];
}

- (void) reachabilityChangedState: (NSNotification* )note {                                     

    // Called by Reachability whenever status changes

    Reachability* curReach = [note object];
    NSParameterAssert([curReach isKindOfClass: [Reachability class]]);

    // HERE I GET THE FOLLOWING WARNING: 'MyViewController' may not respond to '-updateViewWithReachability.' 
    [self updateViewWithReachability: curReach];    
}

- (void) updateViewWithReachability: (Reachability*) curReach {
    ...  // do my thing with controls
}

I think you will have to place the method above, not below, the reachabilityChangedState method to have it recognized.

If that doesn't help, try placing the following in the .h file:

-(void) updateViewWithReachability: (Reachability*) curReach;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM