0

我在使用 Apple 的可达性类时遇到问题。我从 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
}
4

1 回答 1

1

我认为您必须将方法放置在reachabilityChangedState 方法上方而不是下方,以使其被识别。

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

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

于 2011-04-15T18:01:29.120 回答