2011-04-04 59 views
-1

我在模擬器上工作,我正在等待設備上的測試,同時等待我希望與您分享我的代碼,希望您能幫我找出造成5警告的原因 我的應用程序由2個類組成:CoreLocationController和GeoLocationViewController。關於使用地理定位類建立的警告

CoreLocationController是假設充當核心位置管理器委託的類。這個類將接收來自包含原始數據的Core Location框架的消息,然後將其傳遞給我們的視圖控制器類。 CoreLocationController.h

#import <Foundation/Foundation.h> 
#import <CoreLocation/CoreLocation.h> 

@protocol CoreLocationControllerDelegate 
@required 
-(void)LocationUpdate:(CLLocation*)location;//Our location updates are sent here 
-(void)locationError:(NSError*)error;//Any errors are sent here 
@end 
@interface CoreLocationController : NSObject<CLLocationManagerDelegate> { 

    CLLocationManager *locMgr; 
    id delegate; 
} 
@property(nonatomic,retain)CLLocationManager *locMgr; 
@property(nonatomic,assign)id delegate; 
@end 

CoreLocationController.m

#import "CoreLocationController.h" 
    @implementation CoreLocationController 

    @synthesize locMgr,delegate; 

    -(id)init{ 

     self=[super init]; 
     if(self!=nil) { 

      self.locMgr=[[[CLLocationManager alloc] init] autorelease];//create new instance of locMgr 
      self.locMgr.delegate=self;//set the delegate as self 

     } 
     return self;  
    } 


    -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation { 


     if([self.delegate conformsToProtocol:@protocol(CoreLocationControllerDelegate)]) { 


      //check if the class assigning itself as the delegate conforms to our protocol. If not,, the message will go now here. Not good 
      [self.delegate LocationUpdate:newLocation]; 

     } 

    } 


    -(void)LocationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { 

     if([self.delegate conformsToProtocol:@protocol(CoreLocationControllerDelegate)]) { 
     //check if the class assigning it self as the delegate conforms to our protocol.If not, the message will go now here. Not good 
      [self.delegate locationError:error]; 
     } 
    } 

    -(void)dealloc { 
     [self.locMgr release]; 
     [super dealloc]; 

    } 
    @end 

GeoLocationViewController.h:

#import <UIKit/UIKit.h> 
#import "CoreLocationController.h" 
@interface GeoLocationViewController : UIViewController <CoreLocationControllerDelegate> { 

    CoreLocationController *CLController; 
    IBOutlet UILabel *locLabel; 

} 
@property (nonatomic,retain)CoreLocationController *CLController; 
@end 

GeoLocationViewController.m:

#import "GeoLocationViewController.h" 

@implementation GeoLocationViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    CLController=[[CoreLocationController alloc] init]; 
    CLController.delegate=self; 
    [CLController.locMgr startUpdatingLocation]; 
} 

-(void)locationUpdate:(CLLocation *)location { 

    locLabel.text=[location description]; 

} 
-(void)locationError:(NSError *)error { 

    locLabel.text=[error description]; 
} 
- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 
- (void)dealloc { 

    [CLController release]; 
    [super dealloc]; 
} 

@end 

現在的警告我:

warning: property 'CLController' requires method '-CLController' to be defined - use @synthesize, @dynamic or provide a method implementation 


warning: property 'CLController' requires the method 'setCLController:' to be defined - use @synthesize, @dynamic or provide a method implementation 


warning: incomplete implementation of class 'GeoLocationViewController' 


warning: method definition for '-LocationUpdate:' not found 


warning: class 'GeoLocationViewController' does not fully implement the 'CoreLocationControllerDelegate' protocol 

最後一個問題,請,如果我的體型successufully運行,但我的代碼沒有展示任何地理位置的信息,我應該等待測試我的構建設備來判斷它?

+0

你連看這裏copypasting他們之前的警告? – mvds 2011-04-04 22:39:20

+0

嗯,好吧例如我不知道是什麼這:警告:不完整的實施'GeoLocationViewController'的意思是,我總是實現一些方法,並留下別人評論:) – Malloc 2011-04-04 22:44:42

回答

1

第一個警告(和接下來的兩個,這是同樣的事情):

warning: property 'CLController' requires method '-CLController' to be defined - use @synthesize, @dynamic or provide a method implementation 

這意味着,你需要@synthesize CLController在@implementation後您的GeoLocationViewController.m文件。它仍然可以工作,不過,因爲你不是引用它的類中的屬性(即你不與self.CLController只是CLController引用它。所以只是把@synthesize CLController @implementation爲GeoLocationViewController.m後。

第二錯誤

warning: incomplete implementation of class 'GeoLocationViewController' 
warning: method definition for '-LocationUpdate:' not found 

沒有指定LocationUpdate在你GeoLocationViewController.h文件的方法。

+0

以及如何:警告:類'GeoLocationViewController'沒有完全實現'CoreLocationControllerDelegate'協議,我應該實現整個協議!或者只是忽略它 – Malloc 2011-04-04 22:50:41

+0

你不應該忽略警告,特別是在Objective-C中,因爲它們通常會導致運行時崩潰,因爲它是一種基於消息的語言 - 許多事情不會產生編譯時錯誤,但會在運行時崩潰。這就是說,是的,我現在看到問題是什麼:在你的委託中,你已經定義了LocationUpdate,但是在你的下面用一個小寫的L來實現它。試着在你的實現中把它改成大寫來匹配協議 – Mirkules 2011-04-04 23:18:11