2013-04-14 85 views
0

我得到這個錯誤:可達無可見@interface聲明選擇startNotifier可達性無可見@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 

回答

2

你拼寫錯誤的方法。既然你是新的,這裏有幾個建議

[self.reach startNotifier]; 

  • 在.h文件替換#import "Reachability.h"@class Reachability改變這一行:

    [self.reach startNotifer]; 
    

    來。

  • 擺脫明確的ivars和明確的@synthesize行。讓編譯器爲你生成這些。這假定你正在使用最新的編譯器/ Xcode。
  • 你的屬性不一致。一個是strong,另一個是retain。如果您使用的是ARC,則兩者都使用strong。如果您正在使用MRC,則兩者都使用retain
  • 標準約定是類名以大寫字母和方法開頭,變量以小寫字母開頭。兩者都應該使用CamelCase。將您的班級更改爲HelloWorldViewController。將networkstatus更改爲networkStatus
+0

嘿!非常感謝你。 :D – megZo

+0

不客氣。查看我更新的答案並提供更多建議。 – rmaddy

+0

輝煌!謝謝 :) – megZo

相關問題