错误消息使用未声明的标识符

时间:2015-05-27 08:05:22

标签: ios objective-c xcode

这是上面的代码:

- (void)viewDidLoad {
[super viewDidLoad];
[self showLoginProcess:false];

#ifdef DEBUG
self.usernameBox.text = @"passenger@test.com";
self.passwordBox.text = @"123456";
NSLog(@"baseUrl = %@", kBaseURL);
#endif

//TODO: check if internet is available




  (void)testInternetConnection
    {
        internetReachableFoo = [Reachability reachabilityWithHostname:@"www.google.com"];

        // Internet is reachable
        internetReachableFoo.reachableBlock = ^(Reachability*reach)
        {
            // Update the UI on the main thread
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"There is an internet connection");
            });
        };
  

第一行 - (void)testInternetConnection给出了一条错误消息   其中说:使用未声明的标识符'testInternetConnection'

感谢。

3 个答案:

答案 0 :(得分:0)

检查此方法上方的括号,半冒号。

此功能上方存在问题。选择此功能并剪切

(CMD + X)

然后检查上面的错误。

在标题(.h)文件中添加函数- (void)testInternetConnection;

答案 1 :(得分:0)

你在var之前缺少类类型。 尝试添加:

可达性* internetReachableFoo = [Reachability reachabilityWit ....,如下所示

- (void)testInternetConnection
{
  Reachability* internetReachableFoo = [Reachability reachabilityWithHostname:@"www.google.com"];

    // Internet is reachable
    internetReachableFoo.reachableBlock = ^(Reachability*reach)
    {
        // Update the UI on the main thread
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"There is an internet connection");
        });
    };

答案 2 :(得分:0)

-(void)testInternetConnection
{
        internetReachableFoo = [Reachability reachabilityWithHostname:@"www.google.com"];

        // Internet is reachable
        internetReachableFoo.reachableBlock = ^(Reachability*reach)
        {
            // Update the UI on the main thread
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"There is an internet connection");
            });
        };
}  // You may be missed your closing bracket