ファイルの int 値を配列から読み取る際に問題が発生しています。これらの int は、さまざまなビューで UILables の値を変更するために使用されます。objectAtIndex:29 まではすべて問題ありません。その後、順序が正しくなく、値が欠落しており、理由がわかりません。ビューごとに配列を作成しようとしましたが、うまくいきませんでした。私が使用するコードは以下のとおりです。誰かが問題を確認できる場合は、感謝します。
-(NSString *) saveFilePath{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [[path objectAtIndex:0] stringByAppendingPathComponent:@"savefilee.plist"];
}
-(void) applicationDidEnterBackground: (UIApplication *) application{
NSArray *values = [[NSArray alloc] initWithObjects:
[NSNumber numberWithInt:smaWin],
[NSNumber numberWithInt:medWin],
[NSNumber numberWithInt:larWin],
[NSNumber numberWithInt:halfBotWin],
[NSNumber numberWithInt:fullBotWin],
[NSNumber numberWithInt:smaSpi],
[NSNumber numberWithInt:larSpi],
[NSNumber numberWithInt:alcPop],
[NSNumber numberWithInt:hp],
[NSNumber numberWithInt:hc],
[NSNumber numberWithInt:bb],
[NSNumber numberWithInt:addUnit],
[NSNumber numberWithInt:borg],
[NSNumber numberWithInt:savedTenValue],
[NSNumber numberWithFloat:addOne],
[NSNumber numberWithFloat:pinCid],
[NSNumber numberWithFloat:pinLag],//nil];
[NSNumber numberWithInt:svdsmaWin],
[NSNumber numberWithInt:svdmedWin],
[NSNumber numberWithInt:svdlarWin],
[NSNumber numberWithInt:svdhalfBotWin],
[NSNumber numberWithInt:svdfullBotWin],
[NSNumber numberWithInt:svdsmaSpi],
[NSNumber numberWithInt:svdlarSpi],
[NSNumber numberWithInt:svdalcPop],
[NSNumber numberWithInt:svdhp],
[NSNumber numberWithInt:svdhc],
[NSNumber numberWithInt:svdbb],
[NSNumber numberWithInt:svdaddUnit],
[NSNumber numberWithInt:savedTenValue],
[NSNumber numberWithInt:warningmessage],
//[NSNumber numberWithInt:continueall],
[NSNumber numberWithInt:continueFemale],
[NSNumber numberWithInt:continueMale],
[NSNumber numberWithFloat:svdpinLag],
[NSNumber numberWithFloat:svdpinCid],
[NSNumber numberWithFloat:svdTotal],
[NSNumber numberWithInt:malesmaWin],
[NSNumber numberWithInt:malemedWin],
[NSNumber numberWithInt:malelarWin],
[NSNumber numberWithInt:malehalfBotWin],
[NSNumber numberWithInt:malefullBotWin],
[NSNumber numberWithInt:malesmaSpi],
[NSNumber numberWithInt:malelarSpi],
[NSNumber numberWithInt:malealcPop],
[NSNumber numberWithInt:malehp],
[NSNumber numberWithInt:malehc],
[NSNumber numberWithInt:malebb],
[NSNumber numberWithInt:maleaddUnit],
[NSNumber numberWithInt:maleborg],
[NSNumber numberWithInt:malesavedTenValue],
[NSNumber numberWithInt:maleaddOne],
[NSNumber numberWithInt:malepinLag],
[NSNumber numberWithInt:malepinCid],
[NSNumber numberWithInt:malehalfpinCid],
[NSNumber numberWithInt:malehalfpinLag],
[NSNumber numberWithFloat:maleaddOne],
[NSNumber numberWithInt:malesvdsmaWin],
[NSNumber numberWithInt:malesvdmedWin],
[NSNumber numberWithInt:malesvdlarWin],
[NSNumber numberWithInt:malesvdhalfBotWin],
[NSNumber numberWithInt:malesvdfullBotWin],
[NSNumber numberWithInt:malesvdsmaSpi],
[NSNumber numberWithInt:malesvdlarSpi],
[NSNumber numberWithInt:malesvdalcPop],
[NSNumber numberWithInt:malesvdhp],
[NSNumber numberWithInt:malesvdhc],
[NSNumber numberWithInt:malesvdbb],
[NSNumber numberWithInt:malesvdaddUnit],
[NSNumber numberWithInt:malewarningmessage],
[NSNumber numberWithInt:continueall],
[NSNumber numberWithInt:continueFemale],
[NSNumber numberWithInt:continueMale],
[NSNumber numberWithInt:malesvdTotal],
[NSNumber numberWithInt:malesvdpinLag],
[NSNumber numberWithInt:malesvdpinCid],
[NSNumber numberWithInt:ukOrUsa],
[NSNumber numberWithInt:ukonce],
[NSNumber numberWithInt:usaonce],
[NSNumber numberWithInt:maleukonce],
[NSNumber numberWithInt:maleusaonce],nil];
[values writeToFile:[self saveFilePath] atomically:YES];
[values release];
}
- (void)viewDidLoad {
//NSNumber *num = [[NSNumber alloc]initWithInt:count];
NSString *myPath = [self saveFilePath];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:myPath];
if (fileExists) {
NSArray *values = [[NSArray alloc] initWithContentsOfFile:myPath];
smaWin = [[values objectAtIndex:0] intValue];
medWin = [[values objectAtIndex:1] intValue];
larWin = [[values objectAtIndex:2] intValue];
halfBotWin = [[values objectAtIndex:3] intValue];
fullBotWin = [[values objectAtIndex:4] intValue];
smaSpi = [[values objectAtIndex:5] intValue];
larSpi = [[values objectAtIndex:6] intValue];
alcPop = [[values objectAtIndex:7] intValue];
hp = [[values objectAtIndex:8] intValue];
hc = [[values objectAtIndex:9] intValue];
bb = [[values objectAtIndex:10] intValue];
addUnit = [[values objectAtIndex:11] intValue];
borg = [[values objectAtIndex:12] intValue];
savedTenValue = [[values objectAtIndex:13] intValue];
addOne = [[values objectAtIndex:14] floatValue];
pinCid = [[values objectAtIndex:15] floatValue];
pinLag = [[values objectAtIndex:16] floatValue];
svdsmaWin = [[values objectAtIndex:17] intValue];
svdmedWin = [[values objectAtIndex:18] intValue];
svdlarWin = [[values objectAtIndex:19] intValue];
svdhalfBotWin = [[values objectAtIndex:20] intValue];
svdfullBotWin = [[values objectAtIndex:21] intValue];
svdsmaSpi = [[values objectAtIndex:22] intValue];
svdlarSpi = [[values objectAtIndex:23] intValue];
svdalcPop = [[values objectAtIndex:24] intValue];
svdhp = [[values objectAtIndex:25] intValue];
svdhc = [[values objectAtIndex:26] intValue];
svdbb = [[values objectAtIndex:27] intValue];
svdaddUnit = [[values objectAtIndex:28] intValue];
warningmessage = [[values objectAtIndex:29] intValue];
//continueall = [[values objectAtIndex:30] intValue];
continueFemale = [[values objectAtIndex:31] intValue];
continueMale = [[values objectAtIndex:32] intValue];
svdpinLag = [[values objectAtIndex:33] floatValue];
svdpinCid = [[values objectAtIndex:34] floatValue];
svdTotal = [[values objectAtIndex:35] floatValue];
malesmaWin = [[values objectAtIndex:36] intValue];
malemedWin = [[values objectAtIndex:37] intValue];
malelarWin = [[values objectAtIndex:38] intValue];
malehalfBotWin = [[values objectAtIndex:39] intValue];
malefullBotWin = [[values objectAtIndex:40] intValue];
malesmaSpi = [[values objectAtIndex:41] intValue];
malelarSpi = [[values objectAtIndex:42] intValue];
malealcPop = [[values objectAtIndex:43] intValue];
malehp = [[values objectAtIndex:44] intValue];
malehc = [[values objectAtIndex:45] intValue];
malebb = [[values objectAtIndex:46] intValue];
maleaddUnit = [[values objectAtIndex:47] intValue];
maleborg = [[values objectAtIndex:48] intValue];
malesavedTenValue = [[values objectAtIndex:49] intValue];
maleaddOne = [[values objectAtIndex:50] intValue];
malepinLag = [[values objectAtIndex:51] intValue];
malepinCid = [[values objectAtIndex:52] intValue];
malehalfpinLag = [[values objectAtIndex:53] intValue];
malehalfpinCid = [[values objectAtIndex:54] intValue];
malesvdsmaWin = [[values objectAtIndex:55] intValue];
malesvdmedWin = [[values objectAtIndex:56] intValue];
malesvdlarWin = [[values objectAtIndex:57] intValue];
malesvdhalfBotWin = [[values objectAtIndex:58] intValue];
malesvdfullBotWin = [[values objectAtIndex:59] intValue];
malesvdsmaSpi = [[values objectAtIndex:60] intValue];
malesvdlarSpi = [[values objectAtIndex:61] intValue];
malesvdalcPop = [[values objectAtIndex:62] intValue];
malesvdhp = [[values objectAtIndex:63] intValue];
malesvdhc = [[values objectAtIndex:64] intValue];
malesvdbb = [[values objectAtIndex:65] intValue];
malesvdaddUnit = [[values objectAtIndex:66] intValue];
malewarningmessage = [[values objectAtIndex:67] intValue];
continueall = [[values objectAtIndex:68] intValue];
continueFemale = [[values objectAtIndex:69] intValue];
continueMale = [[values objectAtIndex:70] intValue];
malesvdTotal = [[values objectAtIndex:71] intValue];
malesvdpinLag = [[values objectAtIndex:72] intValue];
malesvdpinCid = [[values objectAtIndex:73] intValue];
ukOrUsa = [[values objectAtIndex:74] intValue];
ukonce = [[values objectAtIndex:75] intValue];
usaonce = [[values objectAtIndex:76] intValue];
maleukonce = [[values objectAtIndex:77] intValue];
maleusaonce = [[values objectAtIndex:78] intValue];
[values release];
}
UIApplication *myApp = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (applicationDidEnterBackground:)name:UIApplicationDidEnterBackgroundNotification object:myApp];
if (continueMale == 0) {
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"Please read App info." message:@"Select the 'Info' button below." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[myAlert show];
[myAlert release];
continueMale = 1;
[super viewDidLoad];
}
[super viewDidLoad];
}