title: Passing data back :Delegate method not called
body: <p>I am working on an app that connects with google docs using oauth 2.0, once the user has connected, He clicks a button that goes to a tableView to show all the documents. For this I am using a segue and passing data forward. Now I want the user to select one document, put a checkmark on it and return to the viewcontroller passing data back and display wich document was selected. I read that for passing data back I needed to use a protocol and a delegate. I followed this: <a href="https://stackoverflow.com/questions/5210535/passing-data-between-view-controllers">Passing Data between View Controllers</a> but my problem is that my delegate method is not being called.</p>
  
  <p>Here is my storyboard, just 2 views, a viewcontroller and a tablaviewvcontroller called <code>VistaTableViewController</code>.</p>
  
  <p><img src="https://i.stack.imgur.com/aFBg9.png" alt="enter image description here"></p>
  
  <p>When the user pushes the authenticate button, He connects with google docs using oauth. When he pushes the "Listar" button the VistaTableViewController appears.</p>
  
  <p>Here is the code of VistaTableViewController.h where a define the protocol:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import "GData.h"
  
  
  @class VistaTableViewController;
  
  @protocol VistaTableViewControllerDelegate &lt;NSObject&gt;
  - (void)loqueselecciono:(VistaTableViewController *)controller didSelectDoc:(NSString *)documento;
  @end
  
  
  @interface VistaTableViewController : UITableViewController &lt;UITableViewDataSource&gt;
  {
      IBOutlet UITableView *tablalistar;
      GDataFeedDocList *mDocListFeed2;
  }
  
  @property (nonatomic, weak) id &lt;VistaTableViewControllerDelegate&gt; delegate;
  @property (nonatomic, strong) NSString *documento;
  @property (nonatomic, retain) GDataFeedDocList *mDocListFeed2;
  
  @end
  </code></pre>
  
  <p>Here is the code of VistaTableViewController.m where I call the delegate method:</p>
  
  <pre><code>#import "VistaTableViewController.h"
  
  
  @implementation VistaTableViewController
  {
      NSInteger selectedIndex;
  }
  
  @synthesize delegate;
  @synthesize documento;
  @synthesize mDocListFeed2;
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
  
      selectedIndex = [[mDocListFeed2 entries] indexOfObject:self.documento];
  }
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
      return [[mDocListFeed2 entries] count];
  }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tablalistar"];
      if (cell == nil) {
          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"tablalistar"];
      }
  
      GDataEntrySpreadsheet *doc = [[mDocListFeed2 entries] objectAtIndex:indexPath.row];
  
      cell.textLabel.text = [[doc title] stringValue];
  
      if (indexPath.row == selectedIndex)
          cell.accessoryType = UITableViewCellAccessoryCheckmark;
      else
          cell.accessoryType = UITableViewCellAccessoryNone;
  
      return cell;
  }
  
  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
  
      [tableView deselectRowAtIndexPath:indexPath animated:YES];
      if (selectedIndex != NSNotFound)
      {
          UITableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:selectedIndex inSection:0]];
          cell.accessoryType = UITableViewCellAccessoryNone;
      }
      selectedIndex = indexPath.row;
  
      UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  
      cell.accessoryType = UITableViewCellAccessoryCheckmark;
  
      GDataEntrySpreadsheet *doc = [[mDocListFeed2 entries] objectAtIndex:indexPath.row];
  
      NSString *theDoc = [[doc title] stringValue];
  
      [self.delegate loqueselecciono:self didSelectDoc:theDoc];
  }
  
  @end
  </code></pre>
  
  <p>Ok, so now I just need to tell ViewController to import VistaTableViewController and conform to its protocol.</p>
  
  <p>here is the code of ViewController.h</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import "GTMOAuth2ViewControllerTouch.h"
  #import "GData.h"
  #import "VistaTableViewController.h"
  
  @interface ViewController : UIViewController &lt;VistaTableViewControllerDelegate&gt;
  
  - (GDataServiceGoogleDocs *)docsService;
  - (void)authorize;
  - (void) mifetch;
  - (IBAction)autenticarse;
  - (IBAction)listar:(id)sender;
  - (void) ticket: (GDataServiceTicket *) ticket finishedWithFeed: (GDataFeedDocList *) feed error: (NSError *) error;
  
  @property (nonatomic, retain) NSString *accessToken;
  @property (nonatomic, retain) GDataFeedDocList *mDocListFeed;
  @property (nonatomic, retain) GDataServiceTicket *mDoclistFetchTicket;
  
  
  @end
  </code></pre>
  
  <p>Then in Viewcontroller.m I implement the delegate method as follows: (I just want to display an alert showing the title of de document that was selected).</p>
  
  <pre><code>- (void)loqueselecciono:(VistaTableViewController *)controller didSelectDoc:(NSString *)documento;
  {
      [self.navigationController popViewControllerAnimated:YES];
  
      UIAlertView *alertView = [ [UIAlertView alloc] initWithTitle:@"doc seleccionado"
                                                           message:[NSString stringWithFormat:@"titulo: %@", documento]
                                                          delegate:self
                                                 cancelButtonTitle:@"Dismiss"
                                                 otherButtonTitles:nil];
  
      [alertView show];
  }
  </code></pre>
  
  <p>and in Viewcontroller.m as well I wrote this to assign self to the delegate.</p>
  
  <pre><code>- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  {
      // Make sure your segue name in storyboard is the same as this line
      if ([[segue identifier] isEqualToString:@"displaydocs"])
      {
          VistaTableViewController *vistatableview = [[VistaTableViewController alloc] init];
  
          vistatableview.delegate = self;
  
          vistatableview = [segue.destinationViewController performSelector:@selector(setMDocListFeed2:) withObject:mDocListFeed];
      }
  }
  </code></pre>
  
  <p>Ok, so I get de tableView displaying all the documents and the user can select one showing de checkmark but the delegate method is not being called so It does not return to the viewcontroller view and no data is passed back.</p>
  
  <p>What am I missing?? Thanks!!</p>