UITableView scrolling is not smooth

前端 未结 6 657
囚心锁ツ
囚心锁ツ 2021-02-01 20:41

I have the smooth scrolling issue at my UITableView with UITableViewCell which contains UIImageView. Similar issues could be found all over the StrackOverflow but none of the pr

6条回答
  •  自闭症患者
    2021-02-01 21:01

    I sub-class Paul Hegarty's CoreDataTableViewController and employ thumbnails of my photos in the CoreDataTableView.

    Look for the examples in Lecture 14 titled FlickrFetcher and Photomania. You will also need to download the CoreDataTableViewController at that same link.

    Make a CoreData Entity with an appropriate title and define whatever attributes (data variables) you want. You will need to define two "Transformable" attributes, one for the photo and one for the thumbnail.

    Then load your thumbnail in the CoreDataTableView:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    

    { NSArray *exceptions = [NSArray arrayWithObjects:@"SCR", @"DNS", @"NT", @"ND", @"NH", nil];

    static NSString *CellIdentifier = @"resultsDisplayCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    MarksFromMeets *athleteMarks = [self.fetchedResultsController objectAtIndexPath:indexPath];
    NSString* date = [ITrackHelperMethods dateToAbbreviatedString:athleteMarks.meetDate];
    NSMutableString *title = [NSMutableString stringWithFormat:@"%@", athleteMarks.markInEvent];
    NSMutableString *subTitle = [NSMutableString stringWithFormat:@"%@ - %@",date, athleteMarks.meetName];
    [title replaceOccurrencesOfString:@"(null)"
                           withString:@""
                              options:0
                                range:NSMakeRange(0, [title length])];
    
    // cell.imageView.image = athleteMarks.photoThumbNail; // Don't like image in front of record.
    
    [cell.textLabel setFont:[UIFont
                             fontWithName:@"Helvetica Neue" size:18]];
    
    [cell.detailTextLabel setFont:[UIFont fontWithName:@"Helvetica Neue" size:16]];
    [cell.detailTextLabel setTextColor:[UIColor grayColor]];
    
    // make selected items orange
    if ([athleteMarks.eventPR integerValue] != 0
        && (![exceptions containsObject:athleteMarks.markInEvent])) {
    
        title = [NSMutableString stringWithFormat:@"%@      (PR)",title];
        [cell.textLabel setTextColor:[UIColor redColor]];
    }
    else if ([athleteMarks.eventSB integerValue] != 0
             && (![exceptions containsObject:athleteMarks.markInEvent])) {
        title = [NSMutableString stringWithFormat:@"%@      (SB)",title];
    
        [cell.textLabel setTextColor:[UIColor orangeColor]];
    } else {
        [cell.textLabel setTextColor:[UIColor grayColor]];
    }
    
    cell.textLabel.text = title;
    cell.detailTextLabel.text = subTitle;
    
    cell.indentationLevel = indentationLevelOne;
    cell.indentationWidth = indentationForCell;
    
    return cell;
    

    }

    If you want, I can send you an example of a Category for an Entity's NSManagedObject Sub-Class. This Category loads the photo and the thumbnail into CoreData Entity. The first time will be slow. However, after that the user should be able to scroll through TableView smoothly and then all the updated results will load automatically. Let me know.

    One nice thing is that CoreData handles all the memory management.

    Good luck!

提交回复
热议问题