tableview不能顺利滚动iOS xcode

时间:2016-05-19 10:00:50

标签: tableview smooth-scrolling smooth

每当我滚动桌面视图并出现一个新单元格时,它就会被卡住一毫秒,每次出现一个新单元格时都会发生这种情况,...我尝试了很多选项..

这就是我在哪里查询我的阵营

- (void) retrieveStrings {

    PFQuery *retrieveAllPictures = [PFQuery queryWithClassName:@"String_Pictures"];
    [retrieveAllPictures includeKey:@"string_owner"];
    [retrieveAllPictures whereKey:@"string_boss" equalTo:[PFObject objectWithoutDataWithClassName:@"String" objectId:original_string_objectID]];
    retrieveAllPictures.limit = [loadingNumber intValue];
    [retrieveAllPictures orderByDescending:@"createdAt"];

    [retrieveAllPictures findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {

                originalString = [[NSArray alloc]initWithArray:objects];
                [self.StringTable reloadData];

        }
    }];
}

这是我在索引路径上的行列

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"originalStringCell";

    OriginalStringTableViewCell *originalCell = [StringTable dequeueReusableCellWithIdentifier:CellIdentifier];

    tempObject = [originalString objectAtIndex:indexPath.row];
    userObject = [tempObject objectForKey:@"string_owner"];
    originalTempString = [tempObject objectForKey:@"string_image"];

 [originalTempString getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        if (!error) {

            originalCell.original_string_image.image = [UIImage imageWithData:data];

            CGFloat ImageWidth = ceil(originalCell.original_string_image.image.size.width);
            CGFloat ImageHeight = ceil(originalCell.original_string_image.image.size.height);
            CGFloat NewWidth = ceil ((ImageWidth / ImageWidth) * StringTable.frame.size.width);
            CGFloat NewHeightImageRow = ceil ((ImageHeight / ImageWidth) * StringTable.frame.size.width);

            originalCell.original_string_image.frame = CGRectMake(0, 53, NewWidth, NewHeightImageRow);
            NSLog(@"%f",NewWidth);

            [originalCell.stringIndicator stopAnimating];
            originalCell.stringIndicator.hidden = YES;

            [SVProgressHUD dismiss];

        }
    }];

    return originalCell;

}

1 个答案:

答案 0 :(得分:0)

我找到了使用SDWEBIMAGE的解决方案。

SDWebImageManager *StringPicturemanager = [SDWebImageManager sharedManager];
    [StringPicturemanager downloadImageWithURL:[NSURL URLWithString:originalTempString.    
        options:0
        progress:^(NSInteger receivedSize, NSInteger expectedSize) {
            // progression tracking code
        }
        completed:^(UIImage *SDWStringImage, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
            if (SDWStringImage) {
                NSLog(@"JAAAAAA %@", SDWStringImage);
                originalCell.original_string_image.image = SDWStringImage;
                CGFloat ImageWidth = ceil(originalCell.original_string_image.image.size.width);
                CGFloat ImageHeight = ceil(originalCell.original_string_image.image.size.height);
                CGFloat NewWidth = ceil ((ImageWidth / ImageWidth) * StringTable.frame.size.width);
                CGFloat NewHeightImageRow = ceil ((ImageHeight / ImageWidth) * StringTable.frame.size.width);
                originalCell.original_string_image.frame = CGRectMake(0, 53, NewWidth, NewHeightImageRow);
                NSLog(@"%f",NewWidth);
                [originalCell.stringIndicator stopAnimating];
                originalCell.stringIndicator.hidden = YES;
                [SVProgressHUD dismiss];
                }
            }];