【发布时间】:2013-10-16 15:14:32
【问题描述】:
我已经在我的应用程序中实现了拉动刷新,当拉动时会启动位置管理器以修复用户位置,然后显示一个显示该位置的模态视图控制器。
我遇到的问题是,在获取用户位置之前显示模态视图控制器,导致空白地图持续几秒钟,直到它被获取和更新。
我有一个保存用户当前位置的属性。在拉动刷新调用“showMap”之前是否可以“保持”直到该属性不为零(即已建立位置),也许如果在设定的时间后无法找到用户,它只会显示错误?我尝试使用“while”循环来不断检查 currentLocation 属性,但这似乎不是正确的做法,而且无论如何也没有用。
这是我在 viewDidLoad 中设置的刷新代码:
__typeof (&*self) __weak weakSelf = self;
[self.scrollView addPullToRefreshWithActionHandler:^ {
int64_t delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[weakSelf showMap];
});
}];
当使用拉刷新时,它会调用这些方法:
- (void)showMap
{
[self.locationManager updateCurrentLocation];
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(finishRefresh) userInfo:nil repeats:NO];
}
- (void)finishRefresh
{
[self.scrollView.pullToRefreshController didFinishRefresh];
[self performSegueWithIdentifier:@"showMap" sender:self];
}
【问题讨论】:
标签: objective-c cllocationmanager pull-to-refresh