文字列に値を代入してから戻すことに問題があります。文字列はクラスのプロパティです。これは、他のビュー コントローラーに引き継ぐ必要があるためです。(私は Core Data を試しましたが、どちらも機能せず、こちらの方が簡単に思えました。)
文字列のクラスは次のとおりです。
.h
@interface GameInformation : NSObject
@property (nonatomic, retain) NSString *word;
@property (nonatomic, retain) NSString *mode;
@end
.m
@implementation GameInformation
@synthesize mode = _mode;
@synthesize word = _word;
@end
ものすごく単純。アプリデリゲートの関連コード:
GameInformation *gameInfo = [GameInformation alloc].init;
optionsView.gameInfo = gameInfo;
oneBox.gameInfo = gameInfo;
twoBox.gameInfo = gameInfo;
などなど、すべてのコントローラーをカバーするまで。オプション ビューでは、文字列の値を設定し、それらの値をテストします。
GameInformation *info = [self gameInfo];
UISegmentedControl *selectMode = [self mode];
UISegmentedControl *gameWord = [self word];
if (selectMode.selectedSegmentIndex == 0)
{
info.mode = @"regular";
} else if (selectMode.selectedSegmentIndex == 1) {
info.mode = @"wordTap";
}
if (gameWord.selectedSegmentIndex == 0)
{
info.word = @"regular";
} else if (gameWord.selectedSegmentIndex == 1) {
info.word = @"hat";
} else if (gameWord.selectedSegmentIndex == 2) {
info.word = @"dog";
} else if (gameWord.selectedSegmentIndex == 3) {
info.word = @"book";
} else if (gameWord.selectedSegmentIndex == 4) {
info.word = @"bus";
} else if (gameWord.selectedSegmentIndex == 5) {
info.word = @"cup";
} else if (gameWord.selectedSegmentIndex == 6) {
info.word = @"pig";
}
NSLog(@"%@", info.mode);
NSLog(@"%@", info.word);
そして、それらが渡されると、ログは null として出力されます。[info setWord:@"regular"]; を試しました。および [info setMode@"regular"]; しかし、それらも機能しませんでした。
テストでnullが返されるため、1つのボックス、2つのボックスなどのコントローラーで文字列を使用しようとはしていません。
そう。私は何を間違っていますか?それとも、間違った木を吠えていますか? そして、先ほど言ったように、これにコア データを使用しようとしてもうまくいきませんでした。これはより単純なアプローチのように思えました。
前もって感謝します!
編集: 迅速なコメントありがとうございます! info で NSLog を実行しましたが、実際には null です。また、宣言を保持ではなくコピーに変更し、alloc ステートメントのドット表記を変更しました。alloc ステートメントは、アプリ デリゲートの didFinsihLaunchingWithOptions にあります。それは間違った場所ですか?
助けてくれてありがとう!