简体   繁体   中英

Remove Indexpaths of UITableView that are off screen - indexPath.row is greater than the size of my array

Is it possible to remove indexpaths of UITableView that are off screen? My case calls for it, and I can't seem to find any methods or answers to remove an IndexPath.row that is off screen. I dont need to remove a cell, but only the indexPaths that are visible cells should remain.

Does this make sense?

Sorry I can't provide any code because I dont know where to start.

in iOS6, a new UITableViewDelegate function was introduced that does just this:

- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;

You can use this something like this:

- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
   if ([tableView.indexPathsForVisibleRows indexOfObject:indexPath] == NSNotFound)
   {
    // This indeed is an indexPath no longer visible
    // Do something to this non-visible cell...
   }
}

If you are using UITableView properly and dequeueing cells using the method...

[tableView dequeueCellWithReuseIdentifier:@"blah" indexPath:indexPath];

then this will already be happening.

The tableview manages which cells are on screen. If you have 1000 rows in your table but only 10 rows on screen at a time then you will only ever have 10 cell objects in memory as those ten are reused for the rows that come onto the screen when others are scrolled off the screen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM