0
我想在發送推文之前等待latitude.text和longtitude.text填充,此代碼正常工作,但我寧願不將tweeting部分放在locationManager中,因爲我也想要有時更新當前位置而不發送推文。我怎麼才能確保在發送推文之前沒有這樣做txt被填充?等待CLLocationManager在發送推文之前完成
- (IBAction)update {
latitude.text [email protected]"";
longitude.text [email protected]"";
locmanager = [[CLLocationManager alloc] init];
[locmanager setDelegate:self];
[locmanager setDesiredAccuracy:kCLLocationAccuracyBest];
[locmanager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
CLLocationCoordinate2D location = [newLocation coordinate];
latitude.text = [NSString stringWithFormat: @"%f", location.latitude];
longitude.text = [NSString stringWithFormat: @"%f", location.longitude];
TwitterRequest * t = [[TwitterRequest alloc] init];
t.username = @"****";
t.password = @"****";
[twitterMessageText resignFirstResponder];
loadingActionSheet = [[UIActionSheet alloc] initWithTitle:@"Posting To Twitter..." delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[loadingActionSheet showInView:self.view];
[t statuses_update:twitterMessageText.text andLat:latitude.text andLong:longitude.text delegate:self requestSelector:@selector(status_updateCallback:)];
[email protected]"";
}
這似乎很複雜,因爲我不知道你在說什麼(我剛剛開始學習目標C 3天前) 我可以只有另一個位置管理函數嗎? – user295944 2010-03-18 21:21:20
它確實不那麼複雜。我不知道你的意思是「另一個位置管理功能」。我以爲你想把你的代碼從位置管理器中移出來,所以我給了你一個辦法。另外,通過使用監聽器,您應用的其他部分可以決定何時註冊或移除監聽器。我建議花一些時間理解一些Objective-C概念(如協議),這可能會幫助您提出解決方案。 – 2010-03-18 22:09:08