title: How to correctly access a variable from another class in Objective C
body: <p>I have looked at various forums trying to find a solution to this problem. I currently have 2 classes, BluetoothViewController and AccountViewController. What I am trying to do is pass an account that the user selects from the AccountViewController to BluetoothViewController, so I can use that string later in the BluetoothViewController. What I have done is create an instance of AccountViewController in BluetoothViewController.h and I have created a property for the string in the AccountViewController.h file. The string that I am trying to access is "account8"</p>
  
  <p>My AccountViewController.h file:</p>
  
  <pre><code>@interface AccountViewController : UIViewController &lt;UITableViewDelegate, UITableViewDataSource&gt;
  {
  
      NSArray     *tableData;
      int         cellValue;
      NSString    *cellContents;
      NSString    *account8;
  
  }
  
  @property (nonatomic, retain) NSArray   *tableData;
  @property (nonatomic, retain) NSString  *cellContents;
  @property (nonatomic, retain) NSString  *account8;
  </code></pre>
  
  <p>My AccountViewController.m file:</p>
  
  <pre><code>#import "AccountViewController.h"
  
  
  @interface AccountViewController ()
  
  @end
  
  // Implementing the methods of ViewController
  @implementation AccountViewController
  
  @synthesize tableData;
  @synthesize cellContents;
  @synthesize account8;
  
  
  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {    
      account8 = [tableData objectAtIndex:indexPath.row];
  
      BluetoothViewController *bluetoothViewController = [[BluetoothViewController alloc] initWithNibName:@"BluetoothViewController" bundle:nil];
      [kAppDelegate setSelectedTabWithTag:-1];
      [self.navigationController pushViewController:bluetoothViewController animated:YES];
  
  }
  </code></pre>
  
  <p>My BluetoothViewController.h</p>
  
  <pre><code>#import "AccountViewController.h"
  
  @interface BluetoothViewController : UIViewController &lt;GKPeerPickerControllerDelegate, GKSessionDelegate&gt;{
  
      AccountViewController   *classobj;
  
  }
  
  
  @property(nonatomic, retain) AccountViewController *classObj;
  </code></pre>
  
  <p>My BluetoothViewController.m file:</p>
  
  <pre><code>#import "AccountViewController.h"
  #import "BluetoothViewController.h"
  
  
  
  @interface BluetoothViewController ()
  
  @end
  
  // Implementing the methods of ViewController
  @implementation BluetoothViewController
  
  - (void)viewDidLoad {
  
      [connect setHidden:NO];
      [disconnect setHidden:YES];
      [super viewDidLoad];
  
      count = 0;
  
      classobj = [[AccountViewController alloc] init];
  
      accountSelected = classobj.account8;
  
      accountSelection.text = accountSelected;
  }
  </code></pre>
  
  <p>When the user selects the row from a table, the contents will be saved in the variable account8. BluetoothViewController will then be called. Now, when BluetoothViewController loads up, the account that was selected by the user is supposed to be shown. However the label returns blank. I am wondering why it does not correctly access the variable saved in AccountViewController.</p>