0

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.

Newbee
  • 3,231
  • 7
  • 42
  • 74

1 Answers1

1

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
 });
});
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
  • thanks for you suggestion, dequeueReusableCellWithIdentifier is always returning nil.. Is it okay? – Newbee Feb 08 '13 at 06:10
  • yes check this que:-http://stackoverflow.com/questions/7567737/dequeuereusablecellwithidentifier-always-returns-nil-for-visible-cells – Nitin Gohel Feb 08 '13 at 06:13
  • 2
    @Newbee, if it's returning nil then it means you never allocate and initialize or you deallocate one before sending dequeueReusableCellWithIdentifier message. – Mikayil Abdullayev Feb 08 '13 at 06:14