Why my tableview is slow?

后端 未结 5 749
不思量自难忘°
不思量自难忘° 2021-01-26 16:50

im making a tableview loaded with some NSArrays, the cell contains two labels and a background image view loaded with a URL image. The problem is that the scrolling of the table

5条回答
  •  忘掉有多难
    2021-01-26 17:13

    load your image like this

    //get a dispatch queue
    dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    //this will start the image loading in bg
    dispatch_async(concurrentQueue, ^{
        NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:mapUrlStr]];
        //this will set the image when loading is finished
        dispatch_async(dispatch_get_main_queue(), ^{
            cell.CellImageView.image = [UIImage imageWithData:imageData]
    
        });
    });
    

提交回复
热议问题