0

したがって、100か所すべてに数値0を格納する辞書がありますが、これらの0を使用して、画像なしで100個の画像を初期化します。後で、別の番号が保存された0(つまり、1)を置き換えると、画像が変更されます。私は次のコードを持っています、それはすべて最後の行まで機能します:

NSMutableDictionary *myDict = [[NSMutableDictionary alloc] init];

for (int i = 1; i <= 100; i ++) {
    if(myDict)
    {
        [myDict setObject:[NSNumber numberWithInt:0] forKey:[NSString stringWithFormat:@"block%.3istored",i]];
    }
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [paths objectAtIndex:0];
NSString *path = [documentPath stringByAppendingPathComponent:@"blocks.save"];
BOOL successfulWrite = [myDict writeToFile: path atomically: YES];
if(successfulWrite == NO);

[myDict setObject:[NSNumber numberWithInt:1] forKey:@"block002stored"];

for (int z = 1; z <= 100; z ++) {

    NSString *mapblock=@"mapblock";
    NSString *blocktocheck=[mapblock stringByAppendingFormat:@"%d",z];

    NSLog(@"%d", z);
    NSLog(@"%@", blocktocheck);

    {if (forKey:@"block%.3zstored" == 0) [@"%@", blocktocheck].image = [[UIImage imageNamed:@""];

}

どんな助けでもいただければ幸いです。

4

1 に答える 1

0

2つのこと。

  1. チェックを送信するオブジェクトを見逃しています... >> if (forKey:@"block ....

  2. 有効なキーを設定する必要があります >> @"block%.3zstored"

に変更します

for (int z = 1; z <= 100; z ++) {
    NSString *mapblock=@"mapblock";
    NSString *blocktocheck=[mapblock stringByAppendingFormat:@"%d",z];
    id key = blocktocheck;

    if ([myDict objectForKey:key] == nil) {
         [myDict setObject:img forKey:key];
     }
 }
于 2012-11-28T16:19:25.743 に答える