当我添加以下行时,我得到:
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/