Reputation: 2223
Is there a way to access a given cell in a table?
For example, if I wanted to access the detail text of only the fourth cell in the table, how do I go about that? Is this mainly done using tags? Thanks!
Upvotes: 0
Views: 161
Reputation: 150755
I don't believe the answers to this question!
Yes you can get the text of the cell by asking the cell. But really? What if the cell is not visible? What if the user is scrolling and the cell goes off the screen?
You have everything you need in the table view's datasource.
Look at this diagram taken from Apple's Core Competencies
By asking the view for the text from a cell you are breaking MVC. You are supposed to ask the model (the datasource, in this case)
Upvotes: 2
Reputation: 2676
Try this:-
NSIndexPath *path = [NSIndexPath indexPathForRow:3 inSection:0];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
Upvotes: -1
Reputation: 13267
UITableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0]];
NSString *detail = cell.detailTextLabel.text
Change indexPathForRow
to the appropriate row number.
Upvotes: 2