我正在尝试从 didUpdateToLocation 方法调用一个方法,如下所示。在我的 buttonUpdate 方法中,我正在更新界面,并试图避免如果我将代码块直接放在 didUpdateToLocation 方法中会导致的延迟。出于某种原因,下面的代码导致我的应用程序崩溃。有谁知道为什么?谢谢!
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation
*)newLocation fromLocation:(CLLocation *)oldLocation {
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
[self performSelectorOnMainThread:@selector(buttonUpdate:) withObject:nil
waitUntilDone:NO];
}
}
最佳答案
我马上看到的一件事是您正在通过此选择器调用您的方法:
“按钮更新:
”
该方法签名中的冒号表示应该传递一些对象(例如“-(void)buttonUpdate:(NSString *)maybeAString
”)。你传递的是 nil,这可能是问题所在(如果该方法期望传递真实的东西 - 而不是 nil - )。
关于iphone - performSelectorOnMainThread 嵌入在 didUpdateToLocation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17233746/