tableview无法顺利滚动iOS xcode



每次我在表视图上滚动并出现一个新单元格时,它都会被卡住大约一毫秒,每次出现新单元格时都会发生这种情况,。。我试了很多选择。。

这是我查询数组的地方

- (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;
}

我已经找到了使用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];
                }
            }];

最新更新