简体   繁体   中英

How to customize a UITableViewCell without any freezing in UITableView

I have customized the table view cell, created nib file and its corresponding .h and .m file. Everything works fine except slowness while scrolling, what could be the problem how can I avoid the freezing?

And

obj = [self.listData objectAtIndex: [indexPath row]];


if (obj != nil) {

    static NSString *CellIdentifier;

    if (obj->status == status1) {
        CellIdentifier = @"Cell_italic";
    } else if (obj->status == status2) {
        CellIdentifier = @"Cell_cent";
    } else {
        CellIdentifier = @"Cell";
    }

    custom_cell *cell = (custom_cell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"custom_cell" owner:self options:nil];
        cell = [nib objectAtIndex:0];

        char file_path[MAX_PATH]; // Holds file path.
        memset(file_path, 0, MAX_PATH);


        // Get path
        // Set Image
        UIImage *cellImage = [UIImage imageWithContentsOfFile:fle_path];

        if (cellImage != nil) {
            [cell.image_view setImage:cellImage];
        } 

        NSString *combined_name = [NSString stringWithCString:obj->combined_name encoding:NSASCIIStringEncoding];
        NSString *email = [NSString stringWithCString:obj->email encoding:NSASCIIStringEncoding];

        // Set name
        if (obj->status == status1)
        {
            cell.name_label.text = combined_name;

            cell.name_label.font = [UIFont fontWithName:@"Georgia-Italic" size:18];
            cell.email_label.text = email;

            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            return cell;
        }

        . . .
        . . .


}

dequeueReusableCellWithIdentifier is always returning nil, Is it right? Without customization I have seen it was not nil many times, now it always returning nil.

image loading each-time that's why Table scroll freezing in UITableView you can implement lazy-loading many way refer bellow links and demos may be its helps you :-

https://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html

https://github.com/rs/SDWebImage //README Section says,how to use it in your app.

https://github.com/nicklockwood/AsyncImageView/

you can also load image in Background Process using UI thread

dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_queue_t mainQueue = dispatch_get_main_queue();
dispatch_async(backgroundQueue,^{
  // background process
  image = [NSData dataWithContentsOfFile:imageName];
  dispatch_async(mainQueue,^{
    // always update GUI from the main thread
    // uiimageview.image = image.... etc
 });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM