使用可达性时收到警告

时间:2011-04-15 17:55:08

标签: iphone xcode reachability

我遇到了Apple的Reachability类问题。我从AppDelate成功使用它,但当我尝试从另一个视图控制器类使用它时,我得到下面的警告,尽管它仍然有效。 任何帮助表示赞赏。 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
}

1 个答案:

答案 0 :(得分:1)

我认为您必须将上述方法(而非下方)置于reachabilityChangedState方法中以使其得到识别。

如果这没有帮助,请尝试将以下内容放在.h文件中:

- (void)updateViewWithReachability :(可达性*)curReach;