0

我收到此错误:没有可见的@interface 可访问性声明选择器 startNotifier

我已经包含了 Reachability.h 和 .m 文件。我对 Objective-C 非常陌生,错误可能真的很小!但任何帮助都会很棒!

我的 helloworldViewController.m

#import "helloworldViewController.h"
#import "Reachability.h"
#import <SystemConfiguration/SystemConfiguration.h>


@interface helloworldViewController ()

@end

@implementation helloworldViewController
@synthesize networkstatus;
@synthesize reach;



#pragma mark Reachability changed


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
        // Check network
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil];
    self.reach = [Reachability reachabilityWithHostName:@"www.apple.com"];
    [self.reach startNotifer];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)reachabilityChanged:(NSNotification*)note
{
    Reachability* r = [note object];
    NetworkStatus ns = r.currentReachabilityStatus;

    if (ns == NotReachable)
    {
        NSString* msg = @"Network problems have rendered the iTunes store inaccessible; please try again later.";
        UIAlertView* av = [[UIAlertView alloc] initWithTitle:nil
                                                     message:msg
                                                    delegate:self
                                           cancelButtonTitle:@"Ok"
                                           otherButtonTitles:nil];
        [av show];
        //[av release];
    }
}


@end

这是我的 helloworldViewController.h

#import <UIKit/UIKit.h>
#import "Reachability.h"

@interface helloworldViewController : UIViewController{


    Reachability* reach;
    IBOutlet UILabel *networkstatus;

}
@property(strong,nonatomic) UILabel *networkstatus;
@property (nonatomic, retain) Reachability* reach;

@end
4

1 回答 1

3

您拼写错误的方法。更改此行:

[self.reach startNotifer];

至:

[self.reach startNotifier];

由于您是新手,这里还有一些建议:

  • #import "Reachability.h"在 .h 文件中替换为@class Reachability.
  • 摆脱显式 ivars 和显式@synthesize行。让编译器为您生成这些。这假设您使用的是最新的编译器/Xcode。
  • 你的属性不一致。一个是strong,另一个是retain。如果您使用 ARC,请同时使用strong两者。如果您使用的是 MRC,请同时使用retain两者。
  • 标准约定是类名以大写字母开头,方法和变量以小写字母开头。两者都应该使用 CamelCase。将您的班级更改为HelloWorldViewController. 更改networkstatusnetworkStatus
于 2013-04-14T19:43:35.527 回答