Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching invisible uitableviewcell

I have a tableview with each cell loaded from a xib. It is in the format UILabel some space and UITextField. On a button click somewhere on the view I need the action to fetch all the textfield values in the UITableView with the labels in a dictionary. The problem is when I alloc a cell and fetch the values from there using indexPath, the code crashes exactly at the indexPath of the cell which is invisible (out of screen bounds).

I would appreciate any good ideas on how to fetch those cells which are not visible on screen.

Thanks!

like image 491
Bourne Avatar asked Jan 18 '26 09:01

Bourne


1 Answers

UITableViewCells are reused when they scroll out of view, so that's probably why it won't let you access attributes of UITableViewCells that are not visible.

An NSDictionary might be your best bet:

  1. Set a tag for each cell's UITextField based on the indexPath.row value during cell creation.
  2. Set the delegate for each UITextField to your view controller.
  3. In the delegate method textFieldDidEndEditing, update your dictionary as such: [dictionary setObject:textField.text forKey:[NSNumber numberWithInt:textField.tag]]

And now you can access an array of your textField values with [dictionary allValues].

like image 176
Erik Asmussen Avatar answered Jan 20 '26 01:01

Erik Asmussen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!