gpt4 book ai didi

ios - 我对这个练习的解决方案似乎太简单了;提示?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:26:11 25 4
gpt4 key购买 nike

我正在学习 Big Nerd Ranch 的 iOS Programming, 2nd Edition,我已经来到第 4 章挑战:标题。该练习暗示我感到困惑;它说我需要做一些我认为不需要做的事情。

到本章的这一点为止,本书以 CoreLocation 为例,向我介绍了委派的概念。在应用程序委托(delegate)中,我添加了一个 CLLocationManager 实例变量并将其委托(delegate)设置为应用程序委托(delegate)。见下文:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
locationManager = [[CLLocationManager alloc] init];

[locationManager setDelegate:self];

[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];

[self.window makeKeyAndVisible];
return YES;
}

我还为 CLLocationManager 实现了两个委托(delegate)方法,如下所示:

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"%@", newLocation);
}

- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSLog(@"Could not find location: %@", error);
}

好的,到目前为止,本章已经引导我完成了所有这些,并且一切正常。现在是练习:

"Using delegation, retrieve the heading information from the CLLocationManager and print it to the console. (Hint: You need to implement at least one delegate method and send another message to the location manager.)"

这就是我感到困惑的地方。首先,在阅读了 CLLocationManager 文档之后,似乎除了我已经完成的两个之外没有要实现的委托(delegate)方法。所以我不知道提示可能指的是什么其他委托(delegate)方法。

其次,似乎我可以简单地通过更新 locationManager:didUpdateToLocation:fromLocation: 的实现来解决这个问题,就像这样:

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"%@", newLocation);
// Updated code below
CLLocationDirection heading = [newLocation course];
NSLog(@"Heading: %f", heading);
}

所以在我看来,实际上我不需要向位置管理器发送更多消息(尽管我确实需要向 newLocation 发送 getter 消息;但那是 CLLocation,而不是 CLLocationManager) .

所以我显然误会了什么。我不是在寻找解决方案——我确实想解决这个问题——但我非常感谢你给我一个提示,告诉我我误解了什么。提前致谢!

最佳答案

我认为他们是要您获取罗盘(磁性)航向。

再次回顾 CLLocationManager 文档。有 -startUpdatingHeading 和 -stopUpdatingHeading 方法以及相应的委托(delegate)方法来从设备获取罗盘航向。

希望对您有所帮助。

关于ios - 我对这个练习的解决方案似乎太简单了;提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6665990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com