我的应用程序获取用户位置,获取坐标,并提供到目的地或起点的距离。所有这些可能的目的地都显示在表视图中,因此我在填充表格的同时获取用户坐标。唯一的问题是,询问用户位置的警告视图出现后便立即消失,根本无法单击它!有没有办法在应用程序首次加载时手动显示此警告?我尝试在应用程序加载时获取用户位置以尝试强制显示警报,但这并没有起作用。
你必须将locationManager变量定义为全局对象。
@interface ViewController : UIViewController
{
CLLocationManager *locationManager;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
}
我遇到了和你一样的情况。
#import @interface ViewController ()
@end
@implementation ViewController @synthesize locManager; // after - (void)viewDidLoad { [super viewDidLoad]; // 加载视图后执行任何其他设置,通常是从nib加载。
//MyLocationService *locManager = [[BSNLocationService alloc]init:nil]; // before. the loc. delegate did not work because the instance became invalid after this method. self->locManager= [[MyLocationService alloc]init:nil]; // after locManager.startService; }