0

At my experiment I need to have reference to first UITableViewCell in tableView. By some action I need to set image and some other cell properties and to keep this state of this only cell even if the tableView will be scrolled. All of this properties can be potentially nulled via scrolling (and they actually are) because of reusing. For set this properties every time cell appears on screen, inside of `-cellForRowAtIndexpath' I tried to catch first cell using:

UITableViewCell *firstCell = (UITableViewCell *)[atableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];

but looks like this way I can only catch every next first cell on next scrollable "screen". So, how can I get ref to first UITableView cell?

Alex Thumb
  • 45
  • 6
  • you can use a different re-use identifier for the first screen, than it be use for other rows. – vikingosegundo Apr 06 '14 at 22:51
  • Thanks @vikingosegundo! If I understand your tip right, I need to set another identifier to this first cell. But question is actually how can I get reference to cell at index path {0;0}? – Alex Thumb Apr 06 '14 at 23:00

2 Answers2

2

If I understand you correctly, you are trying to do something special if the cell at (0, 0) is about to be displayed, right? If that's the case, you can easily implement UITableViewDelegate's tableView:willDisplayCell:forRowAtIndexPath: method as follows:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
  if (indexPath) {
    // Do something special
  }
}

There is also a corresponding tableView:didEndDisplayingCell:forRowAtIndexPath: method if you need to undo things.

Hope it helps!

Raymond Law
  • 1,188
  • 1
  • 10
  • 14
0

There is no "first" table view cell. The entire table view typically uses a single cell to improve performance.

You can change that, by implementing your own cell reuse system (search for reuse in the documentation). But generally the cell is the wrong place to store any data related to a specific index in the table view.

Abhi Beckert
  • 32,787
  • 12
  • 83
  • 110
  • Thanks, @Abhi!. By first cell I mean cell which index path is {0;0} at particular moment. I am not trying to store data or something, I am trying to prevent changing cell's properties (visual appearance) values during scrolling – Alex Thumb Apr 06 '14 at 22:56
  • 1
    You could use a different re-use identifier. Check if the index path is `{0,0}` and then use `@"first-cell"` or something. Then it will be a different cell, which you can depend on only being used for that index path. – Abhi Beckert Apr 06 '14 at 22:58