2009-07-03 45 views
0

我一直堅持這幾天,並想知道如果任何人有任何線索?應該很簡單,但它讓我卡住了!我得到我的位置,然後繼續。但我希望保持這種方法 - 循環 - 直到我獲得有效位置。然後loadview。感謝任何提示!loadview只有當我得到我的GPS位置

我使用的標準:

- (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); 

    } 


} 

回答

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; 
} 

您的視圖仍然處於啓動畫面等待狀態,但在您準備好之前,沒有人可以與其進行交互。