title: passing data between views
body: <p>So i'm trying to pass data between two views (first view is tableViewController,when cell is pressed data is send to second view,second view got imageView, when data is send image is shown) using this tutorial <a href="http://www.iphonedevsdk.com/forum/iphone-sdk-development/54859-sharing-data-between-view-controllers-and-other-objects-link-fixed.html" rel="nofollow">iphonedevsdk</a>. </p>
  
  <p>I'm using same <strong>theAppDataObject</strong> method in my views:</p>
  
  <pre><code>- (AppDataObject*) theAppDataObject
  {
      id&lt;AppDelegateProtocol&gt; theDelegate = (id&lt;AppDelegateProtocol&gt;) [UIApplication sharedApplication].delegate;
      AppDataObject* theDataObject;
      theDataObject = (AppDataObject*) theDelegate.theAppDataObject;
      return theDataObject;
  }
  </code></pre>
  
  <p>When cell is pressed i'm trying to send data <code>theAppDataObject.imageString = tempImageString;</code>:</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
      tempImageString = (((championList *) [self.champions objectAtIndex:indexPath.row]).championImage);
  
      AppDataObject *theDataObject = [self theAppDataObject];
      NSLog(@"tempIm-g = %@",tempImageString);
      theDataObject.imageString = tempImageString;
      NSLog(@"theAppDataObject.imageString = %@",theDataObject.imageString);
  
      [self.navigationController popToRootViewControllerAnimated:YES];
  }
  </code></pre>
  
  <p><strong>NSLog output</strong>:</p>
  
  <p>tempIm-g = Champ_0.jpg</p>
  
  <p>theAppDataObject.imageString = (null)</p>
  
  <p><strong>SecondViewController (show image)</strong>:</p>
  
  <pre><code>-(void)viewWillAppear:(BOOL)animated
  {
      AppDataObject* theDataObject = [self theAppDataObject];
      UIImage *tempImage = [UIImage imageNamed:theDataObject.imageString];
      NSLog(@"temp image = %@",tempImage);
      [choosenChampionImageView setImage:tempImage];
  }
  </code></pre>
  
  <p><strong>NSLog output:</strong></p>
  
  <p>temp image = (null)</p>
  
  <p>My problem is that theAppDataObject.imageString is always null</p>
  
  <hr>
  
  <p>Possible solutions that i know:</p>
  
  <p>Do not use AppDataObject as generic data container and just save data in appDelegate.</p>
  
  <p>Ex.:</p>
  
  <pre><code>AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
  appdelegate.imageString = tempImageString;
  </code></pre>
  
  <p>But i want to figure out how to use protocols.</p>
  
  <p>What i tried:
  Make theDataObject global:</p>
  
  <p><strong>view1.h</strong></p>
  
  <pre><code>@interface championsListTableViewController : UITableViewController
  {
      NSString *tempImageString;
  
      AppDataObject* theDataObject;
  }
  
  @property(strong,nonatomic) NSString *tempImageString;
  
  @property(strong,nonatomic) AppDataObject* theDataObject;
  </code></pre>
  
  <p><strong>output</strong> of  NSLog(@"theDataObject is %@",theDataObject); :</p>
  
  <p>theDataObject is (null), how is this possible?</p>