-6

我想在我的应用程序的地图顶部添加这个 UI,以显示驾驶员当前的驾驶速度。我在 main.m 中得到这些错误。为什么,我该如何解决?

使用未声明的标识符 'viewSpeed'
实例方法 '-setViewSpeed:' 未找到(返回类型默认为 'id')
locationmanager.m
预期的 ':'
预期的方法主体
预期的标识符或 '('
缺少 '@end'

#import "locationManager.h"

@implementation locationManager
@synthesize locationManager;
@synthesize fastView;

- (id) init {
    self = [super init];
    if (self != nil) {
        self.locationManager = [[[CLLocationManager alloc] init] autorelease];
        self.locationManager.delegate = self; // send loc updates to myself
    }
    return self;
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    NSLog(@"Location: %@", newLocation description);
{
    self.currentLocation = newLocation;

    BOOL newLocationIsValid = [self isValidLocation:newLocation witholdLocation:oldLocation];
    if(newLocationIsValid && oldLocation)
    {
        int distance = [newLocation distanceFromLocation:oldLocation];
        if(distance >2 && distance<10)
        {
            [self.fastView setText:[NSString stringWithFormat:@"%i meters ", distance]];
        }

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)errort
{
    NSLog(@"Error: %@", [error description]);
}

@end

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    NSLog (@"%s", __func__);
}

主文件

-(void)userDidLoagin
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)dealloc
{
    [userMap release];
    [_Speed release];
    [viewSpeed release];
    [_fastView release];
    [super dealloc];
}

- (void)viewDidUnload
{
    [userMap release];
    userMap = nil;
    [self setSpeed:nil];
    [self setViewSpeed:nil];
    [self setFastView:nil];
    [super viewDidUnload];
}
4

3 回答 3

3

哇。你需要退后两步,回顾一下iOS 应用程序的基本架构。

如果您声称在 main.m 中的代码确实在 main.m 中,那么您的应用程序的结构根本不正确。事实上,在几乎所有 iOS 应用程序中,您根本不应该接触 main.m 文件。这些显然是实例方法实现,这意味着它们应该在类的@implementation 中。

于 2013-07-11T03:15:43.077 回答
1

改变这个:

NSLog(@"Location: %@", newLocation description);

{

对此:

{

NSLog(@"Location: %@", newLocation);

(注意我把它移到了{and之后descirption)。

这将解决您遇到的错误。

于 2013-07-11T01:08:43.107 回答
0

在我看来 viewSpeed 不是一个属性,因为它不是合成的,也没有以 self 开头。或 _ 当它在 dealloc 中使用时。因此,您尝试调用的方法不存在。将该行更改为

viewSpeed = nil;

它应该可以解决您的问题。

编辑:没有看到 viewSpeed 也未声明。您需要将其声明为 ivar 或属性。话虽如此,在您发布的代码中,您似乎没有在任何地方使用它,那么为什么还要发布它并将其设置为 nil 呢?您的@end 似乎也放错了位置,它位于“locationManager:”方法之上。

于 2013-07-11T01:10:08.640 回答