this 튜토리얼의 소스 코드를 다운로드하고 조금만했습니다. 모두 정상적으로 작동합니다.위치 및 제목이 작동하지 않습니다.
이제 위치와 제목을 구현하는 자체 프로젝트를 만들고 싶습니다. 그러나 모두 작성한 후에는 효과가 없습니다. 나는 정상에 GPS 표시가 보이지 않는다.
나는 다른 응용 프로그램을 실행할 때 그 알았어. Xcode는 오류나 경고를 제공하지 않습니다.
내 코드 : (AppDelegate에서 아무 것도 변경하지 않음).
LocationAndHeadingTestViewController.h
#import <UIKit/UIKit.h>
#import "LocationController.h"
@interface LocationAndHeadingTestViewController : UIViewController <LocationControllerDelegate>
{
LocationController *_locationController;
IBOutlet UILabel *_errorLabel;
//Location
IBOutlet UILabel *_locationTimeLabel;
IBOutlet UILabel *_latitudeLabel;
IBOutlet UILabel *_longitudeLabel;
IBOutlet UILabel *_altitudeLabel;
//Heading
IBOutlet UILabel *_headingTimeLabel;
IBOutlet UILabel *_trueHeadingLabel;
IBOutlet UILabel *_magneticHeadingLabel;
IBOutlet UILabel *_headingAccuracyLabel;
IBOutlet UIImageView *_compass;
}
@property (nonatomic, retain) LocationController *locationController;
@end
LocationAndHeadingTestViewController.m
#import "LocationAndHeadingTestViewController.h"
@implementation LocationAndHeadingTestViewController
@synthesize locationController = _locationController;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
_locationController = [LocationController new];
_locationController.delegate = self;
[_locationController.locationManager startUpdatingLocation];
[_locationController.locationManager startUpdatingHeading];
}
- (void)locationUpdate:(CLLocation *)location
{
[_locationTimeLabel setText:[NSString stringWithFormat:@"%@", location.timestamp]];
[_latitudeLabel setText:[NSString stringWithFormat:@"%f", location.coordinate.latitude]];
[_longitudeLabel setText:[NSString stringWithFormat:@"%f", location.coordinate.longitude]];
[_altitudeLabel setText:[NSString stringWithFormat:@"%f", [location altitude]]];
}
- (void)headingUpdate:(CLHeading *)heading
{
[_headingTimeLabel setText:[NSString stringWithFormat:@"%@", heading.timestamp]];
[_trueHeadingLabel setText:[NSString stringWithFormat:@"%f", heading.trueHeading]];
[_magneticHeadingLabel setText:[NSString stringWithFormat:@"%f", heading.magneticHeading]];
[_headingAccuracyLabel setText:[NSString stringWithFormat:@"%f", heading.headingAccuracy]];
}
- (void)locationError:(NSError *)error
{
_errorLabel.text = [error description];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (void)dealloc
{
[_locationController release];
[super dealloc];
}
@end
LocationController.h
#import <CoreLocation/CoreLocation.h>
@protocol LocationControllerDelegate
@required
- (void)locationUpdate:(CLLocation *)location;
- (void)headingUpdate:(CLHeading *)heading;
- (void)locationError:(NSError *)error;
@end
@interface LocationController : NSObject <CLLocationManagerDelegate>
{
CLLocationManager *_locationManager;
id _delegate;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic, assign) id delegate;
@end
LocationController.m
상당히 간단하지만 나는 정말로 뭔가를 간과한다고 생각합니다.
ps. A는 속성을 "유지"의
_locationManager = [[CLLocationManager new] autorelease];
을 : 나는 ...> 당신은 CLLocationManager 객체를 autoreleasing하지 않아야
좋은 설명이 효과가있었습니다. 정말 고마워. – Justin