【问题标题】:Objective C: strange error when init a variable declared in my header file目标C:初始化头文件中声明的变量时出现奇怪的错误
【发布时间】:2010-12-04 19:45:00
【问题描述】:

当我添加这一行时我得到了:

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

【问题讨论】:

    标签: iphone objective-c compiler-errors


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      您没有将 CoreLocation 框架添加到您的项目中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-04-27
        • 1970-01-01
        • 1970-01-01
        • 2016-06-03
        • 1970-01-01
        • 2012-06-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多