Ios 更新OneWLocation时保持为NULL

Ios 更新OneWLocation时保持为NULL,ios,null,cllocationmanager,Ios,Null,Cllocationmanager,但我把它作为输出 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSDateFormatter * formatter = [[[NSDateFormatter alloc] init] autorelease]; [formatter setDate

但我把它作为输出

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation
{
NSDateFormatter * formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm"];

NSString *latitude =  [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude];
NSString *longitude =  [NSString stringWithFormat:@"%f", newLocation.coordinate.longitude];
NSString *stringFromDate = [formatter stringFromDate:newLocation.timestamp];

resultsLabel.text = [NSString stringWithFormat:@"(%@) %@ Location %.06f %.06f %@", ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) ? @"bg" : @"fg", resultsLabel.tag == 0 ? @"gps:" : @"sig" , newLocation.coordinate.latitude, newLocation.coordinate.longitude, [formatter stringFromDate:newLocation.timestamp]];

NSLog(@"%@", resultsLabel.text);

LocationTestAppDelegate * appDelegate = (LocationTestAppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate log:resultsLabel.text];




}
关于:

有人知道我做错了什么吗

       NSLog(@"%@", resultsLabel.text);
在我的委托中,我在这里设置了resultLabel:

  - (id) initWithLabel:(UILabel*)label
{
resultsLabel = label;
return [super init];
}
- (void) log:(NSString*)msg
{
 NSDateFormatter * formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
NSString * logMessage = [NSString stringWithFormat:@"%@ %@", [formatter stringFromDate:[NSDate date]], msg];
NSString * fileName = [self locationPath];
FILE * f = fopen([fileName UTF8String], "at");
fprintf(f, "%s\n", [logMessage UTF8String]);
fclose (f);}
编辑

我删除了GPS功能

有人知道在新的地点如何使用正确的NSLog吗。经纬度时间戳

编辑2

我在这里设置了resultlabel:

  - (id) initWithLabel:(UILabel*)label
{
resultsLabel = label;
return [super init];
}
- (void) log:(NSString*)msg
{
 NSDateFormatter * formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
NSString * logMessage = [NSString stringWithFormat:@"%@ %@", [formatter stringFromDate:[NSDate date]], msg];
NSString * fileName = [self locationPath];
FILE * f = fopen([fileName UTF8String], "at");
fprintf(f, "%s\n", [logMessage UTF8String]);
fclose (f);}
@接口位置委派:NSObject
{
UILabel*结果标签;
NSString*\u电话号码;
}
-(id)initWithLabel:(UILabel*)标签;
//-(id)initWithDictionary:(NSDictionary*)dict;
//-(id)initWithName:(NSString*)aName;
//-(NSDictionary*)toDictionary;
@属性(非原子,保留)NSString*phonenumber;

您的
init
代码很奇怪。这更常见:

@interface  LocationDelegate : NSObject <CLLocationManagerDelegate> 
{
UILabel * resultsLabel;
NSString * _phonenumber;


}

- (id) initWithLabel:(UILabel*)label;
//-(id)initWithDictionary:(NSDictionary *)dict;
//-(id)initWithName:(NSString *)aName;
//-(NSDictionary *)toDictionary;

@property (nonatomic , retain) NSString *phonenumber;
然后通过
self.resultsLabel
访问我假定的实例变量


大概您的问题是当您尝试设置它的文本时,
resultslab
已经是
nil
。向
nil
发送消息没有任何作用,甚至不会给出错误。

如何初始化结果标签?检查是否为空,我在这里设置:UILabel*resultsLabel;我在哪里检查resultsLabel=nil?
NSLog(@“Results Label:%@”,resultsLabel)
,无论您想在何处实际使用该标签。您可能应该在
viewDidLoad
中创建结果标签,或者使用界面生成器并连接插座。