loadview只有当我得到我的GPS位置时

时间:2009-07-03 16:07:33

标签: iphone loadview

我被困在这几天,想知道是否有人有任何线索?应该很简单,但它让我卡住了!我得到了我的位置,然后继续。但我想保持这种方法 - 循环 - 直到我得到一个有效的位置。然后加载查看。感谢任何提示!

我正在使用标准:

- (id)init
{
    if (self = [super init])
    {
        self.locationManager = [[[CLLocationManager alloc] init] autorelease];
        self.locationManager.delegate = self; // send loc updates to myself
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        [self.locationManager startUpdatingLocation];
    }

    return self;
}



- (void)viewDidLoad
{


 // do my processing here ONLY when I get a valid location***************************  
 // and if I never get a valid location, then just go to my last location.



 }



(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSDate* eventDate = newLocation.timestamp;
    NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];

    if (abs(howRecent) < 5.0)

    {

        [manager stopUpdatingLocation]

         printf("latitude %+.6f, longitude %+.6f\n", newLocation.coordinate.latitude, newLocation.coordinate.longitude);

    } 


}

1 个答案:

答案 0 :(得分:3)

不是在viewDidLoad中旋转,而是在获得GPS位置之前建立临时视图怎么样?

// custom full-screen view class of your choice
//  could just be a UIImageView if you wanted
SplashOverlay *splash;

- (void)viewDidLoad {
    [super viewDidLoad];

    splash = [[SplashOverlay alloc] initWithNibName:@"SplashOverlay" bundle:nil];

    [self.view addSubview:splash.view];
}

// do this code to get rid of the view
- (void) doneWithSplashScreen {
    [splash.view removeFromSuperview];
    [splash release];
    splash = nil;
}

您的视图仍会在启动屏幕下等待,但在您准备好之前,没有人可以与它进行互动。