私は本当に奇妙な状況に陥っています。 isChecked 『:「私は名前のBOOL変数を使用してNSUserDefaultsに保存されている特定の条件をご確認のinitメソッドではシングルトンオブジェクトのWierdの動作
static Profile *currentProfile;
+ (Profile *)currentProfile
{
@synchronized(self)
{
if (currentProfile == nil)
currentProfile = [[Profile alloc] init];
}
return currentProfile;
}
- (id)init
{
self = [super init];
if (self)
{
// Initialization code here.
isChecked = [[[NSUserDefaults standardUserDefaults] objectForKey:@"isChecked"] boolValue];
if (isChecked)
{
NSLog(@"isChecked block is called");
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"myEncodedObjectKey"];
self = (Profile *) [NSKeyedUnarchiver unarchiveObjectWithData:data];
[self retain];
for (int i = 0; i < self.avatar.count; i++)
[self.avatar replaceObjectAtIndex:i withObject:[UIImage imageWithData:[self.avatar objectAtIndex:i]]];
}
else
{
password = @"";
pfefferID = @"";
email = @"";
avatar = [[NSMutableArray alloc] initWithObjects:
[UIImage imageNamed:@"empty_image.png"],
[UIImage imageNamed:@"empty_image.png"],
[UIImage imageNamed:@"empty_image.png"],
[UIImage imageNamed:@"empty_image.png"],
[UIImage imageNamed:@"empty_image.png"],nil];
isBoy = YES;
friends = [[NSMutableDictionary alloc] init];
rating = 0;
}
}
return self;
}
このようなプロファイル』にisCheckedがYESに等しく、すべてが正常に動作します私は名前のクラスのsingletoneオブジェクトを作成します。 。しかし...私が使用しているときにモーメントが(今よりもはるかに少ない、実際に)前にYESに等しかったと同じにisChecked変数がNOに等しい取得します。このよう
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
users = [[NSMutableDictionary alloc] init];
usersForLeaderboardFromServer = [[NSMutableDictionary alloc] init];
listOfFriendsFromServer = [[NSMutableDictionary alloc] init];
currentProfile = [Profile currentProfile];
sessionID = 0;
if (!currentProfile.isChecked)//why????
NSLog(@"not checked");
if (currentProfile.isChecked)
{
[self getUsersForLeaderboardFromServer];
MainMenuView *mainMenu = [[[MainMenuView alloc] init] autorelease];
[self.navigationController pushViewController:mainMenu animated:YES];
}
}
ファイルAppDelegateで、このプロファイルオブジェクトを作成しますアプリケーションでは、ドットでアクセスしてFinishedLinunchingWithOptionsメソッドを実行しました。何が起こっていますか?私はそれを処理することができますが、私はちょうど好奇心が強いですこの状況。何が間違っているか知っていますか?
ああ愚かな私、それは明らかです...ありがとう.. –