How to disable table view reload while scrolling in iOS

I want to disable table reload when scrolling. Now my application, when the user scrolls uitableview,, has cellForRowAtIndexPathbeen called. How to disable it when srcolling? Please give me some advice. Thanks in advance.

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = [NSString stringWithFormat:@"%d,%d",indexPath.section,indexPath.row];

    UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    UILabel *FileNameLabel;
    UILabel *UploadTimeLabel;

    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        CFileNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 130, 30)];
            UploadTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 20, 130, 25)];


        FileNameLabel.tag = 1000;
        FileNameLabel.backgroundColor = [UIColor clearColor];
        FileNameLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
        FileNameLabel.font = [UIFont boldSystemFontOfSize:14];
        FileNameLabel.textColor = [UIColor blackColor];
        //  FileNameLabel.text =[temp objectAtIndex:indexPath.row];
        [cell.contentView addSubview: FileNameLabel];
        [FileNameLabel release];


        UploadTimeLabel.tag = 2000;
        UploadTimeLabel.backgroundColor = [UIColor clearColor];
        UploadTimeLabel.font = [UIFont fontWithName:@"Helvetica" size:12];
        UploadTimeLabel.textColor = [UIColor grayColor];
        // UploadTimeLabel.text = [UploadTimeArray objectAtIndex:indexPath.row];
        [cell.contentView addSubview: UploadTimeLabel];
        [UploadTimeLabel release];


    }

    if( [OriginalArray count] > 0)
    {
        UILabel *fileNameLbl = (UILabel*)[cell.contentView viewWithTag:1000];
        //fileNameLbl.text =[temp objectAtIndex:indexPath.row];
        fileNameLbl.text =[[OriginalArray valueForKey:@"FILENAME"] objectAtIndex:indexPath.row];

        UILabel *uploadlbl = (UILabel*)[cell.contentView viewWithTag:2000];
        uploadlbl.text =[[OriginalArray valueForKey:@"UPLOADTIME"] objectAtIndex:indexPath.row];

    }
    _tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

    return cell;
}
+4
source share
4 answers

You cannot block a call cellForRowAtIndexPath:while scrolling through a table. If something does not necessarily happen every time, you can keep it in a state.

 if (cell == nil)
    {
        //Functionality goes here when it not needed to happen every time.
    }
+3
source

Do not use the method UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"yourID"];orUITableViewCell *cell = [tableView dequeueCellWithReuseIdentifier:nil];

. , . .:)

+1

use the dequecellforrowatindex method to avoid reloading cells.

+1
source

Instead of trying to avoid a reboot, perhaps you could play with your data source so that it displays as the data does not change. I hope you understand what I mean.

0
source

Source: https://habr.com/ru/post/1535869/


All Articles