며칠 동안이 문제가 발생하여 해결책을 찾지 못하는 것 같습니다. 아마 아주 기본적인 것들이지만 여전히 해결책을 찾을 수는 없습니다. 그래서 나는 uilabel을 자동차 또는 자전거로 사용자 속도를 업데이트하려고 노력하고 있습니다. 그러나 UIlabel 업데이트 할 때 올바른 값을 업데이트하지 않습니다. 어떤 도움을 주시면 감사하겠습니다. Heres는 내 .H 파일UIlabel이 현재의 사용자 속도를 업데이트하지 않습니다
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface MainViewController : UIViewController <LoginDelegate,WEPopoverParentView,PopoverControllerDelegate,MainMenuDelegate,MKMapViewDelegate,UIActionSheetDelegate,UIAccelerometerDelegate, CLLocationManagerDelegate, NSObject>
{
AppDelegate *appDelegate;
IBOutlet MKMapView *userMap;
CLLocationManager *locationManager;
}
@property (strong, nonatomic) IBOutlet UILabel *speedView;
@property(nonatomic) int speedCount;
@property (nonatomic,retain) CLLocationManager *locationManager;
@property (nonatomic, strong) WEPopoverController *popoverController;
+ (NSString *) speedToMPH: (float) value;
- (IBAction)btnMenuTapped:(id)sender;
@end
내 .H 파일
@implementation MainViewController
@synthesize speedCount;
@synthesize speedView;
@synthesize popoverController;
@synthesize locationManager;
- (void)locationError:(NSError *)error {
speedView.text = [error description];
}
-(void)viewWillAppear:(BOOL)animated
{
[userMap setRegion:MKCoordinateRegionMakeWithDistance(userMap.userLocation.coordinate, 5, 5) animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate = [[UIApplication sharedApplication] delegate];
locationManager =[[CLLocationManager alloc] init];
// Do any additional setup after loading the view, typically from a nib.
[userMap setCenterCoordinate: userMap.userLocation.coordinate animated: YES];
[self performSelector:@selector(checkForLogin) withObject:nil afterDelay:1];
[self startLocationServices];
// create LM
self.locationManager = [CLLocationManager new];
// set its delegate
[self.locationManager setDelegate:self];
// set configuration
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[self.locationManager setDistanceFilter:kCLDistanceFilterNone];
// start location services
[self.locationManager startUpdatingLocation];
// create an oldLocation variable if one doesn't exist
}
- (void)startLocationServices
{
// create the Location Manager
if (self.locationManager == nil) {
self.locationManager = [CLLocationManager new];
}
// stop services
[self.locationManager stopUpdatingLocation];
[self.locationManager setDelegate:nil];
self.speedView.text = @"Location Services stopped.";
}
// locationManager didUpdateToLocation FromLocation
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
NSLog(@"%@", newLocation);
self.speedView.text = [NSString stringWithFormat:@"%d %.f ", speedCount, [newLocation speed]];
}
+ (NSString *) speedToMPH: (float) value
{
NSString *speedCount = @"0.0 ";
if (value>0) {
float mile = 1609.344f;
float mph = value/mile * 3600;
speedCount = [NSString stringWithFormat: @"%.f ", mph];
}
return speedCount;
}
어떻게 올바른 값이 아닌지 알고 계십니까? 표시된 값은 무엇이고 볼 가치가있는 값은 무엇입니까? –
그래서 운전하면서 전화로 시험해 보았습니다. 그래서 나는 30mph로 갈 것이고 myuilabel에서 나는 17.3에 운전하고 있다고 말할 것입니다. 어떤 아이디어 왜 – mrorgon
@mrios 귀하의 질문은 xcode 또는 아이폰과 아무 상관이 없습니다. 이것이 태그가 제거 된 이유입니다. – rmaddy