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