我正在重构我的代码以使其更易于管理我想创建一个包含可以加载到其他类中的函数的类。
我创建了一个名为函数的类,将 funtions.h 导入到我的 ViewController 类的 .h 中,将函数 .m 导入到 ViewController.m 但编译器在调用 hasInternetconnection 时无法识别该方法并崩溃。
我并没有完全迷失为什么我不能在这个类中调用这个方法
这是我的代码,我已经通过 s/o 和 google 仔细查看了,但我仍然看不出我做错了什么
函数.h
#import <Foundation/Foundation.h>
@interface Functions : NSObject
-(BOOL)hasInternetConection;
@end
函数.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;
主视图控制器.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;
}
...