所以我有一个字典,它在所有 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:@""];
}
任何帮助,将不胜感激。