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"
My AccountViewController.h file:
@interface AccountViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
NSArray *tableData;
int cellValue;
NSString *cellContents;
NSString *account8;
}
@property (nonatomic, retain) NSArray *tableData;
@property (nonatomic, retain) NSString *cellContents;
@property (nonatomic, retain) NSString *account8;
My AccountViewController.m file:
#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];
}
My BluetoothViewController.h
#import "AccountViewController.h"
@interface BluetoothViewController : UIViewController <GKPeerPickerControllerDelegate, GKSessionDelegate>{
AccountViewController *classobj;
}
@property(nonatomic, retain) AccountViewController *classObj;
My BluetoothViewController.m file:
#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;
}
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.