使用Geolocation类进行构建时出现警告

时间:2011-04-04 22:30:03

标签: iphone

我在模拟器上工作,我正在等待设备上的测试,等待我希望与您分享我的代码希望您帮助我找出 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

最后一个问题,如果我的构建成功运行,但我的代码没有显示任何有关地理位置的信息,我应该等待测试我在设备上的构建来判断吗?

1 个答案:

答案 0 :(得分:1)

第一个警告(以及接下来的两个警告):

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

这意味着,在@implementation之后,你需要在你的GeoLocationViewController.m文件中@synthesize CLController。但它仍然可以工作,因为你没有将它作为类中的属性引用(即你没有引用它self.CLController而只引用CLController。所以只需将@synthesize CLController放在@ { GeoLocationViewController.m的实现。

第二个错误

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

您没有将LocationUpdate指定为GeoLocationViewController.h文件中的方法。