我制作了一个包含一些单词的 ap 列表,现在我尝试从该 plist 中显示一个随机单词
这是我的代码
NSArray *randomAddons = [NSArray arrayWithContentsOfFile: @"wordsENG.plist"];
int randomIndex = arc4random() % [randomAddons count];
mainTextController.text = [username2 stringByAppendingString:[randomAddons objectAtIndex:randomIndex]];
这会崩溃,当我更改 % [randomAddons count]; 至 % 3; 它崩溃了,但我不知道如何正确编码,有人可以帮我吗?
谢谢
编辑:
根据提供的链接jackjr300,我编辑的plist文件有问题,看下面的评论。我仍然面临着从一开始就遇到的崩溃。崩溃说:
Array: (
(
SAMSAM,
SELSEL,
DONDON
)
)
2012-07-10 03:41:11.048 spinningyarn[1590:1bb03] -[__NSCFArray length]: unrecognized selector sent to instance 0xcfcfdd0
2012-07-10 03:41:11.048 spinningyarn[1590:1bb03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray length]: unrecognized selector sent to instance 0xcfcfdd0'
*** First throw call stack:
(0x1b04022 0x1ee0cd6 0x1b05cbd 0x1a6aed0 0x1a6acb2 0x1468bd9 0x115dc3 0x3de995 0x979ed9 0x981725 0x8ea4ab 0x9837c6 0x8c9885 0x2166330 0x2168509 0x1a3b803 0x1a3ad84 0x1a3ac9b 0x26287d8 0x262888a 0xb3d626 0x29e2 0x2955 0x1)
terminate called throwing an exception(lldb)
SAMSAM、SELSEL、DONDON 是我的 P 列表文件中的 3 个单词