title: How to pass string from a text field (embedded in a table cell) in 2nd controller back to a label in 1st controller (also embedded in a table cell)?
body: <p><strong>Edit 1:</strong> I think I have figured out the problem, I just haven't been able to solve it. In SecondViewController.m where textFieldShouldReturn is defined, "if ([self.delegate respondsToSelector:@selector(passString:)])" returns false, since NSLog was not triggered.</p>
  
  <p><strong>Edit 2:</strong> Checking NSLogs of who is the delegate in both ViewControllers gave good insight to the problem. In the FirstViewController, prepareForSegue assigns the correct delegate. After the segue to SecondViewController, delegate becomes "null".</p>
  
  <p>This is something I have been trying to achieve for a week without success. I do understand that I need to pass the data back up the two-layer navigation stack using delegates. However, I'm not sure why my code does not work (string does not get passed).</p>
  
  <p>It would be also much appreciated if anyone can tell me (links and other resources) how to properly make a Form/Submission View (2nd Controller) for data entry that can be reused for to edit specific cell's labels in the Display View (1st Controller).</p>
  
  <p>Here is my code:</p>
  
  <p><strong>SecondViewController.h</strong></p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @protocol PassStringDelegate
  - (void)passString:(NSString *)stringFromTextField;
  @end
  
  @interface SecondViewController : UIViewController &lt;UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate&gt;
  
  @property (strong, nonatomic) IBOutlet UITableView *detailTable;
  
  @property (weak, nonatomic) id &lt;PassStringDelegate&gt; delegate;
  
  @end
  </code></pre>
  
  <p><strong>SecondViewController.m</strong></p>
  
  <pre><code>#import "SecondViewController.h"
  #import "CustomCell.h" // My cell is custom built in IB.
  
  @interface SecondViewController ()
  
  @end
  
  @implementation SecondViewController
  
  @synthesize delegate;
  
  @synthesize stringFromTextField;
  
  - (void)viewDidLoad
  {
      ...            
      NSLog(@"%@", self.delegate);                          // Returns "(null)".
  }    
  
  ...
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Data Entry" forIndexPath:indexPath];
      [cell setEditing:YES animated:YES];
      cell.customTextField.clearsOnBeginEditing = NO;
      cell.customTextField.returnKeyType = UIReturnKeyDone;
      cell.customTextField.delegate = self;                 // customTextField is a custom textfield embedded in the custom cell.
      [self textFieldShouldReturn:cell.customTextField];    // This function supposedly will trigger passString:stringFromTextField when the cell is done with editing.
  
      return cell;
  }
  
  ...
  
  - (BOOL)textFieldShouldReturn:(UITextField *)textField
  {
      [textField resignFirstResponder];
      if ([self.delegate respondsToSelector:@selector(passString:)]) {
          [self.delegate passString:textField.text];
          NSLog(@"Sent back: %@", textField.text);          // I checked NSLog, this was never called.
      }
      return YES;
  }
  </code></pre>
  
  <hr>
  
  <p><strong>FirstViewController.h</strong></p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import "SecondViewController.h"
  
  @interface FirstViewController : UIViewController &lt;UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, PassStringDelegate&gt;
  
  @property (strong, nonatomic) IBOutlet UITableView *table;
  
  @property (copy, nonatomic) NSArray *myList;
  
  @property (weak, nonatomic) NSString *obtainedString;
  
  @end
  </code></pre>
  
  <p><strong>FirstViewController.m</strong></p>
  
  <pre><code>#import "FirstViewController.h"
  #import "CustomCell.h"
  
  @interface FirstViewController ()
  
  @end
  
  @implementation FirstViewController
  
  @synthesize obtainedString;
  
  ...
  
  - (void)viewDidAppear:(BOOL)animated
  {
      [super viewDidAppear:animated];
      [self passString:obtainedString];
  }
  
  ...
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Display" forIndexPath:indexPath];
      cell.customLabel.text = obtainedString;             // I want the label to display the text in the text field in the second controller.
      cell.detailCustomLabel.text = self.myList[indexPath.row];
  
      return cell;
  }
  
  ...
  
  - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  {
      if ([segue.identifier isEqualToString:@"segue"])
       {
          SecondViewController *detailedView = [[SecondViewController alloc] init];
          detailedView.delegate = self;
          NSLog(@"%@", detailedView.delegate);            // Returns "&lt;SecondViewController: 0x10967b590&gt;".
       }
  }
  
  ...
  
  - (void)passString:(NSString *)stringFromTextField
  {
      obtainedString = stringFromTextField;
  }
  </code></pre>
  
  <p>Please check my delegate path and calls to see if what I did was close to appropriate.
  Thank you very much!</p>