我在模擬器上工作,我正在等待設備上的測試,同時等待我希望與您分享我的代碼,希望您能幫我找出造成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運行,但我的代碼沒有展示任何地理位置的信息,我應該等待測試我的構建設備來判斷它?
你連看這裏copypasting他們之前的警告? – mvds 2011-04-04 22:39:20
嗯,好吧例如我不知道是什麼這:警告:不完整的實施'GeoLocationViewController'的意思是,我總是實現一些方法,並留下別人評論:) – Malloc 2011-04-04 22:44:42