我有一段代码在 plist 中找到一个随机单词,然后将其分配给 NSString 'correctWord'。由于某种原因,代码在一个实例中运行良好,但在另一个实例中不起作用。
此代码有效:
- (void) viewDidLoad
{
NSString *path = [[NSBundle mainBundle] pathForResource:
@"small" ofType:@"plist"];
NSArray *plistArray = [[NSArray alloc] initWithContentsOfFile:path];
NSInteger randV = arc4random_uniform(plistArray.count); // randV is from 0 to number of strings -1 in array
[super viewDidLoad];
self.correctWord = @"Hello"; //<--- Code works fine here..
[self setupHangmanWord:self.correctWord];
}
此代码不起作用。(虽然编译器没有错误)
- (void) viewDidLoad
{
NSString *path = [[NSBundle mainBundle] pathForResource:
@"small" ofType:@"plist"];
NSArray *plistArray = [[NSArray alloc] initWithContentsOfFile:path];
NSInteger randV = arc4random_uniform(plistArray.count); // randV is from 0 to number of strings -1 in array
[super viewDidLoad];
self.correctWord = [plistArray objectAtIndex:randV]; //<--- Doesn't work anymore.
[self setupHangmanWord:self.correctWord];
}