Ios 没有方法的应用程序运行良好,但我认为它需要方法才能正常运行
我有一个位置应用程序,在过去几天的ViewController.m文件头中有以下方法:Ios 没有方法的应用程序运行良好,但我认为它需要方法才能正常运行,ios,objective-c,xcode5,cllocationmanager,cllocation,Ios,Objective C,Xcode5,Cllocationmanager,Cllocation,我有一个位置应用程序,在过去几天的ViewController.m文件头中有以下方法: -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations; 然而,我刚刚从代码中删除了上述内容,应用程序仍然运行100%良好。当xcode文档清楚地说这种方法的目的是“告诉代理何时有新的位置数据可用”时,我不明白这是怎么可能的 我能想到的唯一一件事是,上面写着“新的位置数据”,并且我
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
然而,我刚刚从代码中删除了上述内容,应用程序仍然运行100%良好。当xcode文档清楚地说这种方法的目的是“告诉代理何时有新的位置数据可用”时,我不明白这是怎么可能的
我能想到的唯一一件事是,上面写着“新的位置数据”,并且我导入的CoreLocation.h文件中已经设置了上述方法,因此已经可以使用,并且已经存储了数据
在我继续之前,我只是想确保我理解了这一切背后的理论
谢谢你帮我清理这件事
这是我的整个ViewController.m代码(方法仍然包括在内):
#导入“ViewController.h”
#进口
@界面视图控制器()
//这会告诉代理新的位置数据可用。Manager是更新事件的对象,locations对象是存储位置数据数组的位置。
-(无效)地点经理:(CLLocationManager*)地点经理更新地点:(NSArray*)地点;
@结束
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
self.gpsLM=[[CLLocationManager alloc]init];
NSLog(@“已启用位置服务:%u”,[CLLocationManager授权状态];
[self.gpsLM startUpdatingLocation];
self.gpsLM.delegate=self;
CLLocation*currentLocation=self.gpsLM.location;
NSLog(@“您当前的位置是:%@”,currentLocation);
}
-(无效)未收到记忆警告
{
[超级记忆警告];
}
-(iAction)GPS按钮{
CLLocation*currentLocation=self.gpsLM.location;
self.gpsLabel.text=[NSString stringWithFormat:@“您的位置是%@”,currentLocation];
NSLog(@“已启用位置服务:%u”,[CLLocationManager授权状态];
NSLog(@“您当前的位置是:%@”,currentLocation);
}
@结束
iOS检查您的类是否能够通过以下方式接收数据:
if ( [delegate respondsToSelector:@selector(didUpdateLocations:)] ){
[delegate performSelector:@selector(didUpdateLocations:) withArgs:....]
}
因此,如果您的委托未实现该方法,则它不会尝试发送该方法。iOS将检查您的类是否能够通过以下方式接收数据:
if ( [delegate respondsToSelector:@selector(didUpdateLocations:)] ){
[delegate performSelector:@selector(didUpdateLocations:) withArgs:....]
}
因此,如果您的委托未实现该方法,则它不会尝试发送该方法。iOS将检查您的类是否能够通过以下方式接收数据:
if ( [delegate respondsToSelector:@selector(didUpdateLocations:)] ){
[delegate performSelector:@selector(didUpdateLocations:) withArgs:....]
}
因此,如果您的委托未实现该方法,则它不会尝试发送该方法。iOS将检查您的类是否能够通过以下方式接收数据:
if ( [delegate respondsToSelector:@selector(didUpdateLocations:)] ){
[delegate performSelector:@selector(didUpdateLocations:) withArgs:....]
}
因此,如果您的委托未实现该方法,则它不会尝试发送该方法。想想看:在您的代码中,当用户点击按钮时,您会获得新的位置,而使用委托方法时,您会在新的位置可用时立即获得新的位置。这就是区别。感谢您的回答。想想看:在您的代码中,当用户点击按钮时,您会得到新的位置,而使用委托方法,您会在新的位置可用时立即得到新的位置。这就是区别。感谢您的回答。想想看:在您的代码中,当用户点击按钮时,您会得到新的位置,而使用委托方法,您会在新的位置可用时立即得到新的位置。这就是区别。感谢您的回答。想想看:在您的代码中,当用户点击按钮时,您会得到新的位置,而使用委托方法,您会在新的位置可用时立即得到新的位置。这就是区别。谢谢你的回答。谢谢你的回答!谢谢你的回答!谢谢你的回答!谢谢你的回答!