我可以在我的主视图中将标签链接到 ViewController.h。但是,在设置屏幕中,程序不会让我将标签输出到 ViewController.h。因此,下面的“testLabel”被标记为未声明的标识符。我希望标签反映用户是否连接到互联网。
视图控制器.h
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import "Reachability.h"
@interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
Reachability *internetReachableFoo;
}
- (IBAction)cameraButtonClicked:(id)sender;
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *testLabel; //Not linked
@end
视图控制器.m
- (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(), ^{
testLabel.text = @"YAY Intrawebs!!";
});
};
// Internet is not reachable
internetReachableFoo.unreachableBlock = ^(Reachability*reach)
{
// Update the UI on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
testLabel.text = @"Someone broke the internet";
});
};
[internetReachableFoo startNotifier];
}