I used the console to check if it reloads and it does in cellForRowAtIndexPath. It causes the table view to get stuck for a moment. I thought it was because of images but now I can’t figure out the problem.
Any help would be great.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog( @"Cell loading" );
static NSString *CellIdentifier = @"showVideo";
CustomVideoCell *cell = (CustomVideoCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell=[[CustomVideoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
}
NSURL *url = [NSURL URLWithString:[data objectForKey:@"profilepicture"]];
NSData *data = [NSData dataWithContentsOfURL:url];
[cell.playimage setImageWithURL:[NSURL URLWithString:[data objectForKey:@"profilepicture"]]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
return cell;
}
This line makes the issue:
This is a synchronous call, that’s why you feel a lag while scrolling.
Never call such methods on main thread, it will cause your app unresponsive. If the data is too high, then it’ll take more time for downloading and thus take more time to respond to UIEvents.
You need to cache the images once it’s downloaded, else each time when the table is reloaded it’ll download it again. If the image is already downloaded you need to display it from the cache don’t download it again. You need to handle this on your
cellForRowAtIndexPath.You can write your own code for doing these tasks or you can rely on the following samples.
Check the following libraries/source code: