UITableViewCells在某些情况下会快速闪烁

时间:2013-11-26 04:54:10

标签: ios objective-c uitableview uirefreshcontrol

我已经花了几个小时在这上面,并且无法弄清楚为什么我的UITableViewCells全部闪烁/闪烁(我可以解释它的唯一方法):

  1. 我的所有帖子都已加载
  2. 我刷新并从数组中删除所有对象并加载第一页刷新结果
  3. 我向下滚动到第一页的末尾,然后将第二页添加到我的数组中。
  4. 我所有的后期闪光/改变位置,然后恢复正常(它真的很快,但看起来很糟糕)
  5. 只有当所有帖子都被加载然后我刷新并且它不会发生在第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];
                }
            }
        }
    }
    

0 个答案:

没有答案