1

I use arc4random in my project. Everything is fine with the functionality.

I want to add some more functionality, like a previous/back button with the arc4random function. I get my string out of an PLIST file and use it with the arc4random. When I touch the screen some random text will appear. I want to include an previous/back button so I can get the text (previous way) that was shown.

Anyone with an idea? Thanks a lot!

Edited: With some code:

NSString *pathToQuestions = [[NSBundle mainBundle] pathForResource:@"Bee" ofType:@"plist"];
NSMutableArray *questions = [[[NSMutableArray alloc] initWithContentsOfFile:pathToQuestions] autorelease];

int questionIndex = arc4random() %[questions count];

NSDictionary *question = [questions objectAtIndex:questionIndex];
NSString *name = [question objectForKey:@"name"];
NSString *sub = [question objectForKey:@"sub"];

nameslbl.text = name;
subslbl.text = sub;
4

1 回答 1

2

如果您使用 生成随机整数arc4random(),那么“返回”的唯一方法是存储函数的输出。你可以NSMutableArray很容易地做到这一点。每次生成新的随机索引时,将其添加到数组的末尾。要返回,只需访问数组中的前一个对象。

于 2012-02-07T17:22:32.903 回答