所以我的图像是在iphone 5s上下载的,但它们并没有出现在手机的iPhone 6中。我使用的是parse.com,但我认为这不是一个解析问题。此外,在iPhone 5s上,当图像在单元格中加载时,它会导致慢速滚动,并且图像在您通过之前不会加载。我知道这是因为我重复使用单元格并且必须加载,但有没有办法加快图像加载,以便在单元格中滚动到它之前显示?任何建议都会很棒。感谢。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object{
NSString *cellIdentifier = @"activityT";
ActTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
object = [self.objects objectAtIndex:indexPath.section];
NSDateFormatter *dateformatter = [[NSDateFormatter alloc]init];
[dateformatter setTimeZone:[NSTimeZone systemTimeZone]];
[dateformatter setDateStyle:NSDateFormatterShortStyle];
NSString *name = [[[object objectForKey:@"fromUser"] objectForKey:@"username"]copy];
NSString *place = [[[object objectForKey:@"location"]objectForKey:@"placename"]copy];
NSString *city = [[[object objectForKey:@"location"]objectForKey:@"city"]copy];
NSString *state = [[[object objectForKey:@"location"]objectForKey:@"state"]copy];
cell.context.text = [object objectForKey:@"recommendationText"];
[[cell name]setTitle:[NSString stringWithFormat:@"@%@",name] forState:UIControlStateNormal];
[[cell placeButton]setTitle:[NSString stringWithFormat:@"%@ (%@,%@)",place,city,state] forState:UIControlStateNormal];
cell.time.text = [formatter stringForTimeIntervalFromDate:[NSDate date] toDate:[object createdAt]];
cell.myImage.image = nil;
cell.myImage.layer.cornerRadius = cell.myImage.frame.size.width / 2;
cell.myImage.clipsToBounds = YES;
cell.myImage.file = [[object objectForKey:@"fromUser" ]objectForKey:@"profileImage"];
[cell.myImage loadInBackground];
cell.layer.cornerRadius = 5;
cell.layer.masksToBounds = YES;
cell.placeImage.image = nil;
cell.placeImage.clipsToBounds = YES;
if ([object objectForKey:@"postImage"]) {
cell.placeImage.file = [object objectForKey:@"postImage"];
if ([cell.placeImage.file isDataAvailable]) {
[cell.placeImage loadInBackground:^(UIImage *image, NSError *error) {
if (!error) {
CGSize size = CGSizeMake(cell.placeImage.frame.size.width, 200);
cell.eventImage.image = [self imageWithImage:image scaledToSize:size];
}
}];
}
}
return cell;
}
- (UIImage*)imageWithImage:(UIImage*)image
scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(newSize.width, newSize.height), NO, 0);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}