iphone - objective-c : strange error when init a variable declared in my header file

标签 iphone objective-c compiler-errors

当我添加以下行时,我得到:

locMan = [[CLLocationManager alloc] init];

对于我的.m文件中的viewDidLoad方法,我遇到了一些以前从未见过的错误。错误如下:

我一生都无法弄清楚为什么添加该行会引起问题。如果有人能阐明一点,我将不胜感激。

我有这个头文件:
#import <UIKit/UIKit.h>
#import "CoreLocation/CoreLocation.h"


@interface RobotWarsViewController : UIViewController 
<CLLocationManagerDelegate> {

    CLLocationManager *locMan;

    // Current Location View
    IBOutlet UIView  *currentLocationView;
    IBOutlet UILabel *currentLocationLabel;


}

@property (assign, nonatomic) UIView  *currentLocationView;
@property (assign, nonatomic) UILabel *currentLocationLabel;
@property (assign, nonatomic) CLLocationManager *locMan;                           

- (IBAction)dropEMP:(id)sender;
- (IBAction)armEMP:(id)sender;

@end

这个.m文件:
#import "RobotWarsViewController.h"

@implementation RobotWarsViewController


@synthesize locMan;
@synthesize currentLocationView;
@synthesize currentLocationLabel;

- (void)viewDidLoad {
    [super viewDidLoad];

    locMan = [[CLLocationManager alloc] init];
//  locMan.delegate = self;

}

- (IBAction)dropEMP:(id)sender{

    NSLog(@"Boo");

}

- (IBAction)armEMP:(id)sender{

    NSLog(@"boo");

}

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

    NSLog(@"location update");

}



- (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)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)dealloc {
    [super dealloc];
    [currentLocationView release];
    [currentLocationLabel release];

}

@end

最佳答案

您是否将CoreLocation框架添加到您的项目中?

展开Frameworks组,然后查看那里是否列出了CoreLocation。如果没有,请右键单击它并添加。

关于iphone - objective-c : strange error when init a variable declared in my header file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4355449/

相关文章:

android-ndk - cygwin 出错 : ffmpeg compile with ndk

ios - 当我在 xcode 中构建我的应用程序时,出现错误 :/bin/sh: bad interpreter: Operation not permitted

iphone - 为 iphone 4 和 5 创建单独的 Storyboard

objective-c - OCMock 一个类方法用自定义数据回调传递的 block

c - 在 apache2 中重新编译 mod\module

c++ - C3861 : Identifier not found; method returning array c++

ios - 如何将 .md 中的开源许可确认添加到 ios 应用程序的确认中

iphone - #error 1107 在 iPhone 上运行 flash 游戏时,使用 Adob​​e Air

javascript - appcelerator titan -TableViewRow selectedBackgroundColor 去除圆 Angular

objective-c - 4.4 中的新 Objective-c 文字