我正在重構我的代碼以使其更易於管理我想創建一個包含可以加載到其他類中的函數的類。導入一類函數頭
我創建了一個名爲functions的類,將funtions.h導入到我的ViewController類的.h中,將函數.m導入到ViewController.m中,但編譯器在調用和崩潰時無法識別hasInternetconnection方法。
我沒有完全喪失,爲什麼我不能在這個類
這裏是我的代碼中調用這個方法,我曾通過S/O良好的外觀和谷歌,我還看不到有什麼我做錯了
Functions.h
#import <Foundation/Foundation.h>
@interface Functions : NSObject
-(BOOL)hasInternetConection;
@end
Functions.m
#import "Functions.h"
@implementation Functions
-(BOOL)hasInternetConection{
NSURL *url=[NSURL URLWithString:@"www.google.com"];
NSURLRequest *req=[NSMutableURLRequest requestWithURL:url];
NSHTTPURLResponse *res=nil;
[NSURLConnection sendSynchronousRequest:req returningResponse:&res error:NULL];
if (res!=nil) {
return NO;
}else{
return YES;}
}
@end
HomeViewController.h
...
#import <QuartzCore/QuartzCore.h>
#import "multiShotViewController.h"
#import "Functions.h"
...
@interface HomeViewController:{的UIViewController
UIGlossyButton *b;
HomeViewController.m
...
#import "detailsViewController.h"
#import "Functions.h"
#define Kwelome @"welcomeread"
@interface HomeViewController()
@end
@class Functions;
@implementation HomeViewController
@synthesize tripName;
@synthesize databasePath, deathtrail;
@synthesize lampingbtn,deerstalkingbtn,boundarybtn, optionsbtn,shootingbtn;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.navigationItem.title = @"Home";
UIColor *backg=[[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"bgcamo.png"]];
self.view.backgroundColor=backg;
[backg release];
}
return self;
}
...
你要在你的HomeViewcontroller中調用' - (BOOL)hasInternetConection'嗎? – Alex