Adam G
Adam G

Reputation: 1188

Objective-C: Getting Value of Property on Non-Visible Custom UITableViewCell

I've been using the code below to access the value of a textfield in my custom UITableViewCell. Problem is, this only works for cells that are visible at the time the method is called.

NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:3];
AppointmentNotesTableViewCell *cell = [self.tableView cellForRowAtIndexPath:path];
NSString *str = cell.notesView.text;

Does anyone have a better way to access this information, regardless of the cell being visible or not?

Upvotes: 0

Views: 33

Answers (1)

Cynichniy Bandera
Cynichniy Bandera

Reputation: 6103

That is because invisible cells do not exist. Cells get reused when you scroll the table view. Only those of them, visible on the screen can actually be accessed.

All the objects that potentially displayable in the table view are normally stored in some kind of list. What you need is to access the object from the list using the index you have from @path instead of trying to access its "rendered copy" from the table view itself.

Upvotes: 1

Related Questions