私はこの問題の解決策を見つけようとしているさまざまなフォーラムを見てきました。現在、BluetoothViewControllerとAccountViewControllerの2つのクラスがあります。私がやろうとしているのは、ユーザーがAccountViewControllerから選択したアカウントをBluetoothViewControllerに渡すことです。これにより、後でBluetoothViewControllerでその文字列を使用できるようになります。私が行ったことは、BluetoothViewController.hにAccountViewControllerのインスタンスを作成し、AccountViewController.hファイルに文字列のプロパティを作成したことです。アクセスしようとしている文字列は「account8」です
私のAccountViewController.hファイル:
@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;
私のAccountViewController.mファイル:
#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];
}
私のBluetoothViewController.h
#import "AccountViewController.h"
@interface BluetoothViewController : UIViewController <GKPeerPickerControllerDelegate, GKSessionDelegate>{
AccountViewController *classobj;
}
@property(nonatomic, retain) AccountViewController *classObj;
私のBluetoothViewController.mファイル:
#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;
}
ユーザーがテーブルから行を選択すると、内容は変数account8に保存されます。その後、BluetoothViewControllerが呼び出されます。これで、BluetoothViewControllerがロードされると、ユーザーが選択したアカウントが表示されるはずです。ただし、ラベルは空白を返します。AccountViewControllerに保存されている変数に正しくアクセスできないのはなぜだろうか。