How do I get the cell for an indexPath which is not currently visible in the table? (cell is out of range)
Code for getting my cell:
NSString *name = [[(ELCTextfieldCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] rightTextField] text];
-cellForRowAtIndexPath...
returns nil
because the cell at the required indexPath is out of range. So how do I get the correct cell and not nil?
Registering the cell To do that we register the XIB file in the view controller that has the UITableView . Then, open HabitsTableViewController. swift to finish registering the cell. Add the following line of code inside the viewDidLoad() method.
Add a table view to your interface. To add a table view to your interface, drag a table view controller ( UITableViewController ) object to your storyboard. Xcode creates a new scene that includes both the view controller and a table view, ready for you to configure and use.
This is not how it works. You need to grab and store the information as soon as it is entered or changed. It may easily get out of scope and you cannot guarantee your cell lives long enough. Well, technically you can hold onto it (and always return the very same cell for the same index path), but I'd question that design.
In continue to @Raphael's answer, Here is the (working) swift 3 solution:
UITableViewCell cell = self.tableView(self.tableView, cellForRowAt: indexPath)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With