开发者

Objective C: strange error when init a variable declared in my header file

开发者 https://www.devze.com 2023-01-29 01:43 出处:网络
I am getting when I add this line: locMan = [[CLLocationManager alloc] init]; To the viewDidLoad method inside of my .m file I get some errors that I have never see开发者_如何学Gon before.Here are

I am getting when I add this line:

locMan = [[CLLocationManager alloc] init];

To the viewDidLoad method inside of my .m file I get some errors that I have never see开发者_如何学Gon before. Here are the errors:

Objective C: strange error when init a variable declared in my header file

I cannot for the life of me figure out why adding that line is causing problems. If anyone can shed some light I would be very grateful.

I have this header file:

#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

And this .m file:

#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


Did you add the CoreLocation framework to your project?

Expand the Frameworks group, and see if CoreLocation is listed there. If not, right click on it, and add.


You didn’t add the CoreLocation framework to your project.

0

精彩评论

暂无评论...
验证码 换一张
取 消