[英]iOS Tableview scroll lagging if location services are ON
我有一個應用程序,使用CLLocationManager實例獲取設備的位置。
現在,當我調用使用self.locationManager.location
的函數來獲取tableview的每個單元格內的位置時。 tableview滾動滯后且斷斷續續。 但是,如果我關閉了對應用程序的位置訪問 ,則一切都會順利進行!
我知道通常由於對HTTP調用或圖像下載的處理不當而導致表格視圖滯后,但是如果是這種情況,那么在關閉該位置的情況下也會發生這種情況。
有人可以在這里闡明一下嗎?
在iOS 9.1和iOS 8.4上測試
更新了cellForRow的代碼。...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@“tableRow” forIndexPath:indexPath];
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObjectOrDoNothing: [AppLoc currentLatitude] forKey:@“latitude”];
[dict setObjectOrDoNothing:[AppLoc currentLongitude] forKey:@“longitude”];
[dict setObjectOrDoNothing:[NSNumber numberWithInteger:indexPath.row] forKey:@“content”];
[[AppManager serviceManager] postDataWithParams:dict];
return cell;
}
使用AFNetworking和lat發布數據的地方,長方法本質上可以做到以下幾點:
[[AppLocationsManager sharedInstance] currentLocation].coordinate.latitude;
[[AppLocationsManager sharedInstance] currentLocation].coordinate.longitude;
您應該獲取沒有單元格的位置,然后調用tableview.reloaddata()
p / s:我認為您應該共享您的代碼,因此很容易獲得幫助
因此,事實證明, locationManager.location
方法特別昂貴,尤其是在高頻使用時(如此處的情況)。 解決它。 我從位置管理器緩存了位置,並指出了所有應用程序組件,甚至表單元格都使用了該緩存的位置,而不是每次都對位置管理器進行調試。
感謝您的所有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.