我正在試圖製作一個應用程序,在該應用程序中,圖片中出現了一個單詞的字謎。我有anagram的一部分,但我不能讓圖片出現。照片保存在名爲「圖像」的文件夾中。我想打電話給anagramPics - 項目0,同時作爲anagrams -item 0 - 以匹配單詞與圖片在plist中存儲圖像路徑,然後檢索以顯示在屏幕上
在此先感謝。對於字謎
代碼:
level.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
level.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
gameController.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);
}
請發表您的代碼。 – ryantxr
我沒有看到任何試圖顯示圖像的代碼。 – ryantxr
這就是我遇到的問題。我不知道該怎麼稱呼它。 – isabella