DifficultySelection で変数 (難易度) を作成しました。CharacterSelection からこの変数に到達しようとすると、結果 = 0 になるため、どこかにカプセル化の問題があると推測しています。
難易度選択.h:
@class CharacterSelection;
@interface DifficultySelection : UIViewController
{
CharacterSelection *charPage;
UIButton *normalDifficulty;
int difficulty;
}
- (IBAction)normalDifficulty:(id)sender;
@property (strong) CharacterSelection *charPage;
@property (strong) DifficultySelection *diffPage;
@property (strong, nonatomic) IBOutlet UIButton *normalDifficulty;
@property (nonatomic, readwrite) int difficulty;
@end
難易度選択.m:
#import "DifficultySelection.h"
#import "CharacterSelection.h"
@interface DifficultySelection ()
@end
@implementation DifficultySelection
@synthesize normalDifficulty, charPage, diffPage, difficulty;
- (IBAction)normalDifficulty:(id)sender {
if (! self.charPage)
self.charPage = [[CharacterSelection alloc] initWithNibName:nil bundle:nil];
self.difficulty = 1;
charPage.diffPage = self;
[self.navigationController pushViewController:self.charPage animated:YES];
}
@end
CharacterSelection.h:
#import "DifficultySelection.h"
@class MainGameDisplay;
@class DifficultySelection;
@interface CharacterSelection : UIViewController <UIScrollViewDelegate> {
MainGameDisplay *openGame;
DifficultySelection *diffPage;
}
@property (nonatomic, readwrite) CharacterSelection *charPage;
@property (strong) DifficultySelection *diffPage;
@property (nonatomic, readwrite) int difficulty;
@end
CharacterSelection.m:
#import "CharacterSelection.h"
#import "MainGameDisplay.h"
@interface CharacterSelection ()
@end
@implementation CharacterSelection
@synthesize diffPage, charPage;
- (void)viewDidLoad
{
self.difficulty = charPage.diffPage.difficulty;
printf("Diff:%i %i", self.difficulty, diffPage.difficulty);
//Both of these output 0, encapsulation problem.
}
@end