title: Pass data from plist based UITableView to UIViewController
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/7562258/how-to-pass-data-to-detail-view-after-being-selected-in-a-table-view">How to pass data to detail view after being selected in a table view?</a>  </p>
  </blockquote>
  
  
  
  <p>I have a TableViewController with a protoptype cell. It's populated with Labels and ImageViews from a .plist with an Array of Dictionaries. How can I pass this data to the detail View? The detail view is a UIViewController subclass.
  I've tried with methods from different tutorials but I just can't find the right combination to make it work. Code examples would be great!</p>
  
  <p>WinesViewController.h</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  @class WineObject;
  
  @interface WinesViewController : UITableViewController {
      WineObject *wine;
  }
  
  @end
  </code></pre>
  
  <p>WinesViewController.m</p>
  
  <pre><code>- (void)viewWillAppear:(BOOL)animated {
  wine = [[WineObject alloc] initWithLibraryName:@"Wine"];
  self.title = @"Vinene";
  [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
  }
  
  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  {
  // Return the number of sections.
  return 1;
  }
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
  // Return the number of rows in the section.
  return [wine libraryCount];
  }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
  static NSString *CellIdentifier = @"wineCell";
  
  //UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  WineCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  
  // Configure the cell...
  
  cell.nameLabel.text = [[wine libraryItemAtIndex:indexPath.row] valueForKey:@"Name"];
  cell.districtLabel.text = [[wine libraryItemAtIndex:indexPath.row] valueForKey:@"District"];
  cell.countryLabel.text = [[wine libraryItemAtIndex:indexPath.row] valueForKey:@"Country"];
  cell.bottleImageView.image = [UIImage imageNamed:[[wine libraryItemAtIndex:indexPath.row] valueForKey:@"Image"]];
  
  return cell;
  }
  </code></pre>
  
  <p>wineobject.m</p>
  
  <pre><code>@implementation WineObject 
  @synthesize libraryContent, libraryPlist;
  
  - (id)initWithLibraryName:(NSString *)libraryName {
  if (self = [super init]) {
      libraryPlist = libraryName;
      libraryContent = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] 
                                                                pathForResource:libraryPlist ofType:@"plist"]];
  }
  return self;
  }
  
  
  - (NSDictionary *)libraryItemAtIndex:(int)index {
  return (libraryContent != nil &amp;&amp; [libraryContent count] &gt; 0 &amp;&amp; index &lt; [libraryContent count]) 
  ? [libraryContent objectAtIndex:index]
  : nil;
  }
  
  - (int)libraryCount {
  return (libraryContent != nil) ? [libraryContent count] : 0;
  }
  
  - (void) dealloc {
  if (libraryContent) [libraryContent release];
  [super dealloc];
  }
  
  @end
  </code></pre>
  
  <p>WineCell.m</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface WineCell : UITableViewCell
  
  @property (nonatomic, strong) IBOutlet UILabel *nameLabel;
  @property (nonatomic, strong) IBOutlet UILabel *districtLabel;
  @property (nonatomic, strong) IBOutlet UILabel *countryLabel;
  
  @end
  </code></pre>