I work yet on simulator and I am waiting for the test on the device, while waiting I wish to share with you my code hoping you to help me figure out the causes of 5 warnings my app is composed from 2 classes : CoreLocationController and GeoLocationViewController .
the CoreLocationController is the class which suppose to act as a Core Location Manager Delegate. This class will receive messages from the Core Location framework containing the raw data and will then pass this to our view controller class later on. 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;
}
-(vo开发者_如何学JAVAid)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
Now for the warnings I got :
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
Last question please, if my build run successufully, but my code doesn't show any informations about geolocation, should I wait to test my build on device to judge on it ??
The first warning (and the next two, which are the same thing):
warning: property 'CLController' requires method '-CLController' to be defined - use @synthesize, @dynamic or provide a method implementation
It means, you need to @synthesize CLController in your GeoLocationViewController.m file after @implementation. It will still work, though, because you are not referencing it as a property inside the class (i.e. you are not referencing it with self.CLController
but just CLController
. So just put @synthesize CLController
after @implementation for GeoLocationViewController.m.
The second error
warning: incomplete implementation of class 'GeoLocationViewController'
warning: method definition for '-LocationUpdate:' not found
You did not specify LocationUpdate as a method in your GeoLocationViewController.h file.
精彩评论