我已经花了几个小时在这上面,并且无法弄清楚为什么我的UITableViewCells全部闪烁/闪烁(我可以解释它的唯一方法):
只有当所有帖子都被加载然后我刷新并且它不会发生在第3 +页,只发生在第2页时,才会发生这种情况。
这是我的代码:
- (void)setup
{
nearbyArray = [[NSMutableArray alloc]init];
nearbyCellHeight = [[NSMutableArray alloc]init];
isLoadingMorePosts = YES;
didLoadAllNearbyObjects = NO;
isRefreshing = NO;
totalNearbyObjects = 0;
querySkip = 0;
[self query];
}
- (void)refreshControlValueChanged:(UIRefreshControl *)refresh
{
NSLog(@"refreshing");
if (!isRefreshing){
didLoadAllNearbyObjects = NO;
isRefreshing = YES;
querySkip = 0;
totalNearbyObjects = 0;
refreshControl = refresh;
[self query];
}
}
- (void)query
{
NSLog(@"loading");
int querylimit = 25;
PFQuery *placeQuery = [PFQuery queryWithClassName:@"places"];
if (querySkip > 0) {
[placeQuery setSkip: querylimit * querySkip];
}
[placeQuery setLimit:querylimit];
[placeQuery whereKey:@"location" nearGeoPoint:[PFGeoPoint geoPointWithLatitude:[LocationController sharedSingleton].locationManager.location.coordinate.latitude longitude:[LocationController sharedSingleton].locationManager.location.coordinate.longitude] withinMiles:
200];
[placeQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error){
[self handleQuery:objects];
}
else{
NSLog(@"Error: %@", error);
isLoadingMorePosts = NO;
}
}];
}
- (void)handleQuery:(NSArray *)objects
{
if (isRefreshing){
[nearbyArray removeAllObjects];
[nearbyCellHeight removeAllObjects];
isRefreshing = NO;
}
[nearbyArray addObjectsFromArray:objects];
//determine if all objects are already loaded
if (totalNearbyObjects != nearbyArray.count)
totalNearbyObjects = nearbyArray.count;
else
didLoadAllNearbyObjects = YES;
isLoadingMorePosts = NO;
[tableView reloadData];
refreshControl.endRefreshing;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentSize.height - scrollView.contentOffset.y < (self.view.bounds.size.height)) {
if (!isLoadingMorePosts) {
if (didLoadAllNearbyObjects == NO){
isLoadingMorePosts = YES;
querySkip++;
[self query];
}
}
}
}