How to create randomly selected NSString “package” for iPhone app

风格不统一 提交于 2019-12-11 08:17:45

问题


I'm just delving into Objective C and Cocoa Touch and I'm trying to build an app for personal use.

My goal is to create an app that displays a randomized NSString in a center window on the iPhone screen while also displaying a scrollable list of associated NSStrings in another window on the side of the screen.

For example: if the center NSString is the name of an animal, such as "Lion", the NSStrings on the list next to it would also be animals (e.g., "Tiger", Snow Leopard", etc.)

I would like to create "packages" of associated NSStrings, have the program randomly select a "package", randomly display one of its NSStrings in the center, and simultaneously display a list of the other NSStrings in the package in the scrollable side window. After a given time interval the program would then loop and select another NSString, excluding those in the previously displayed "package".

My main interest is how to create such "packages" of NSStrings. Is it feasible to use NSDictionary or NSArray to create them?

Since I am just starting out I am hoping that someone can point me in the right direction in my research so that I know what tools I should use to begin experimenting.

I'd very much appreciate any recommendations or example code.

Thanks!


回答1:


Use both NSArray and NSDictionary for it.

For example:

NSArray *animalArray = [NSArray arrayWithObjects:@"cat", @"dog", ... , nil];
NSArray *drinkArray = [NSArray arrayWithObjects:@"coke, @"tea", ... , nil];
...

NSMutableDictionary *wordsDictionary = [[NSMutableDictionary alloc] init];
[wordsDictionary addObject:animalArray forKey:@"animal"];
[wordsDictionary addObject:drinkArray forKey:@"drink"];
...

And you can get all keys using [NSDictionary allKeys]



来源:https://stackoverflow.com/questions/9371529/how-to-create-randomly-selected-nsstring-package-for-iphone-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!