IBActionsでインクリメントする多くのint値を使用するiPhoneアプリがあります。アプリを閉じるときにint値を配列に保存して、これらの値が保存され、アプリを再度開いたときに使用されるようにします。int値を配列に書き込む方法がわかりません。機能的には、これはテキストフィールドで麦汁になりますが、整数ではありません。
intカウント;
使用したコード:
NSArray *values = [[NSArray alloc] initWithObjects:fieldOne.text,fieldTwo.text,count, nil];
これにより、「代入はキャストなしでポインタから整数になります」というメッセージが表示されます。
とにかく、すでに格納されているint値を配列に書き込むことはできますか?私が使用したコードは次のとおりです。
データを配列に呼び出すまでは問題ないと思います。私はいくつかの失敗した努力をコメントアウトしました
-(NSString *) saveFilePath{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [[path objectAtIndex:0] stringByAppendingPathComponent:@"savefile.plist"];
}
-(void) applicationDidEnterBackground: (UIApplication *) application{
//NSNumber *num = [[NSNumber alloc]initWithInt:count];
NSArray *values = [[NSArray alloc] initWithObjects:fieldOne.text,fieldTwo.text,[NSNumber numberWithInt:count],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];
fieldOne.text = [values objectAtIndex:0];
fieldTwo.text = [values objectAtIndex:1];
//[NSNumber count intValue] = [values objectAtIndex:2];
[values release];
}
UIApplication *myApp = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector (applicationDidEnterBackground:)name:UIApplicationDidEnterBackgroundNotification object:myApp];
[super viewDidLoad];
}
ご協力ありがとうございました。