z22
z22

Reputation: 10083

tableView reloadData/reloadRowsAtIndexPaths causes scroll flickering

I have a tableView with custom prototype cells with 50 rows. On Load more click, next 50 records should be loaded.

Now the first 50 records are scrolled smoothly, but on load more call, I call reloadData on tableView. Now the tableView scrolling is not smooth. I logged the indexes, I get the following log when I continously scroll upwards:

 index: 44
index: 43
index: 48
index: 49
index: 44
index: 43
index: 42
index: 47 // scrolls back causing flicker
index: 48 

I also tried reloadRowsAtIndexPaths, still the same.

How do I solve this? Where am I getting wrong? I am using autolayout, is it causing the issue?

edited code

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellProp" forIndexPath:indexPath];

//assign cell content

    return cell;
}

Upvotes: 0

Views: 841

Answers (2)

Nguyen Hoan
Nguyen Hoan

Reputation: 1693

try:

let cell = tableView.dequeueReusableCellWithIdentifier("yourCellIdentifier", forIndexPath: indexPath)

And You should not tableview.ReloadData() when load more. Using:

tableView.insertRowsAtIndexPaths([indexpaths], withRowAnimation: UITableViewRowAnimation.Left)

Upvotes: 0

Aklesh Rathaur
Aklesh Rathaur

Reputation: 1847

Try to use

dequeueReusableCellWithIdentifier:forIndexPath:

Upvotes: 1

Related Questions