Earl Grey
Earl Grey

Reputation: 7466

Alternative method for getting reference to a UITableviewCell?

The design of the app I am working on, specifically the tableview part is quite complicated. There are around 5-6 methods in which I need to get a reference to particular cell from the table view. What I do not like is that I have to use the

-tableview:cellForRowAtIndexPath

This is a datasource method and does a lot of heavy lifting. Custom cell configuration, dequeueing, getting data for particular cell..etc.. The point is all this code is executed again,even if it does not make any sense at all. The cell object is completely loaded already. Am I right in my observation and if yes, is there a working tested and lightweight solution?

Perhaps there could be an index of references to all cells. Asking it, I would immediately get the reference without the datasource code.

Upvotes: 0

Views: 954

Answers (1)

Kreiri
Kreiri

Reputation: 7850

UITableView has cellForRowAtIndexPath: method.

From UITableView reference:

Returns the table cell at the specified index path.

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath

Parameters
indexPath
The index path locating the row in the receiver.

Return Value
An object representing a cell of the table or nil if the cell is not visible or indexPath is out of range.

Upvotes: 2

Related Questions