According to the Apple Documentation near cellForRowAtIndexPath: it returns "An object representing a table cell or nil if the cell is not visible or indexPath is out of range."
A UITableViewCell is a view according to the MVC Pattern . Therefore, I would prefer to save the model object - perhaps it's as simple as an NSString instance - to save the text in a cell if I were you. You can observe the change in UITextField by adding an observer to the UITextFieldTextDidChangeNotification button to your controller.
- (void)textFieldDidChangeText:(NSNotification *)notification { // Assume your controller has a NSString (copy) property named "text". self.text = [(UITextField *)[notification object] text]; // The notification object property will return the UITextField instance who has posted the notification. } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Dequeue cell... // ... if (!cell) { // Init cell... // ... [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidChangeText:) name:UITextFieldTextDidChangeNotification object:yourTextField]; } // Other code... // ... return cell; }
Remember to remove the observer in -dealloc .
source share