ここでは、1回の実行が完了すると、スコアがデフォルトのスコアエントリまたは新しく配置されたスコアよりも高い場合、他のすべてを押し下げる。リストから最後のエントリを削除します。現在のところこれはちょうど1つの交換であり、機能のために私はそれをハードコーディングして、後でそれをリファクタリングするつもりです。該当する場合は、名前を入力する際に問題が発生しています
私の主な問題は、プレイヤーの名前を取得するためにテキスト入力ビューを設定すると、プレイヤーの入力がなくてもすぐに実行され、ゲームがクラッシュすることです。私はテキストを設定する行をコメントアウトしました。なぜなら、私が試みようとする試みが失敗した場合のために、デフォルト値があるからです。入力が行われている間、実行を少し待つことができますか?デリゲートメソッドを設定する必要がありますか?もしそうなら、私はまだ代表者によって混乱しています。私はそれを動作させることができますが、私はそれを理解していないので、他の特別なカスタムタスクを実行することはできません。私はヘルプをいただければ幸いです...
-(void)saveData:(ScoreKeep *)stats{
NSMutableDictionary *swap = [[NSMutableDictionary alloc]init];//used for swaping entries
NSString *filePath = [self pathOfFile];
NSLog(@"Writing to %@", filePath);
if ([[NSFileManager defaultManager]fileExistsAtPath:filePath]) {
NSLog(@"Loading previous dictionary to save...");
dataDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
if ([dataDictionary objectForKey:@"1"]) {
NSMutableDictionary *highScore = [dataDictionary objectForKey:@"1"];
if ([stats.score intValue] > [[highScore objectForKey:@"SCORE"] intValue]) {
NSLog(@"You Win! score: %@ highscore: %@", stats.score,[NSNumber numberWithInt:[[highScore objectForKey:@"SCORE"] intValue]]);
stats = [[ScoreKeep alloc] initWithNibName:@"Scorekeep" bundle:nil];
NSLog(@"Setting up name entry");
[self.view addSubview:stats.view]; //New view is added so that the player can input data(Assume it is complete);
//stats.nameTag = setName.nameTag;//This line is executed before the new view is dismissed causing an error to occur
[stats setupDictionary]; // It just goes down hill from here if the previous line is uncommented
[dataDictionary setObject:stats.sComponents forKey:@"1"];
}else {
NSLog(@"You Lose: %@ highscore: %@", stats.score,[NSNumber numberWithInt:[[highScore objectForKey:@"SCORE"] intValue]]);
}
NSLog(@"Got first place entry");
}else {
NSLog(@"Initilizing Score");
}
}else{
NSLog(@"Creating new dictionary to save...");
dataDictionary = [[NSMutableDictionary alloc]init];
}
[dataDictionary writeToFile:filePath atomically:YES];
}
をしばらくの間、それに取り組んで、それ以上の得なかっました。より多くの情報が必要な場合は、私が提供してくれることを嬉しく思います。 ScoreKeepが、それは私が必要とする任意の値を設定し、sComponentsにそれらをパッケージ化することができるように辞書を作成する辞書機能が含まれているオブジェクト(辞書は、メインセーブファイルに入力する)
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@class omphalosUtility;
#pragma mark -
#pragma mark Saving data
#pragma mark -
static inline void poop(){
NSLog(@"POOP");
}
である方法によって
私はファイルを更新し、必要に応じて保存などの他の汎用操作を実行できるように、アプリケーションとは独立して動作するユーティリティファイルを作成しようとします。それは私が取るべき方向への一歩です。
表示用にコードを正しくフォーマットしてください。私はそれを修正しようとしましたが、すべてのネストされたifをあきらめました。 – Abizern
ええ、それは私がそれを修正したコードをうんざりさせて申し訳ありません。 – Ohmnastrum
途中で乱雑なコーディングができて申し訳ありません。私はクラスにすべての機能を組み込むことを計画していましたので、それほど悪夢ではありません。 – Ohmnastrum