我正在尝试制作一个应用程序,其中图片带有单词的字谜。我有字谜部分,但我无法显示图片。图片保存在名为“images”的文件夹中。我想在 anagrams -item 0 的同时调用 anagramPics - item 0 - 将单词与图片匹配
提前致谢。
字谜的代码:
水平.m
#import "Level.h"
@implementation Level
+(instancetype)levelWithNum:(int)levelNum;
{
// find .plist file for this level
NSString* fileName = [NSString stringWithFormat:@"level%i.plist", levelNum];
NSString* levelPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
// load .plist file
NSDictionary* levelDict = [NSDictionary dictionaryWithContentsOfFile:levelPath];
// validation
NSAssert(levelDict, @"level config file not found");
// create Level instance
Level* l = [[Level alloc] init];
// initialize the object from the dictionary
l.pointsPerTile = [levelDict[@"pointsPerTile"] intValue];
l.anagrams = levelDict[@"anagrams"];
l.timeToSolve = [levelDict[@"timeToSolve"] intValue];
return l;
}
@end
级别.h
#import <Foundation/Foundation.h>
@interface Level : NSObject
//properties stored in a .plist file
@property (assign, nonatomic) int pointsPerTile;
@property (assign, nonatomic) int timeToSolve;
@property (strong, nonatomic) NSArray* anagrams;
//factory method to load a .plist file and initialize the model
+(instancetype)levelWithNum:(int)levelNum;
@end
游戏控制器.h
-(void)dealRandomAnagram
{
//1
NSAssert(self.level.anagrams, @"no level loaded");
//2 random anagram
int randomIndex = arc4random()%[self.level.anagrams count];
NSArray* anaPair = self.level.anagrams[ randomIndex ];
//3
NSString* anagram1 = anaPair[0];
NSString* anagram2 = anaPair[1];
//4
int ana1len = [anagram1 length];
int ana2len = [anagram2 length];
//5
NSLog(@"phrase1[%i]: %@", ana1len, anagram1);
NSLog(@"phrase2[%i]: %@", ana2len, anagram2);
}