如何创建随机选择的NSString“package” iPhone应用程序 [英] How to create randomly selected NSString "package" for iPhone app

查看:111
本文介绍了如何创建随机选择的NSString“package” iPhone应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是深入研究Objective C和Cocoa Touch,我试图建立一个个人使用的应用程序。



我的目标是创建一个应用程序,在iPhone屏幕上的中心窗口中显示随机NSString,同时在另一个窗口中显示相关NSStrings的可滚动列表



例如:如果中心NSString是动物的名称,例如Lion,则它旁边的列表中的NSStrings也将是动物(例如Tiger,Snow Leopard等)



我想创建相关NSStrings的packages,让程序随机选择一个 ,在中心随机显示一个NSStrings,同时在可滚动侧窗口中显示包中的其他NSStrings的列表,在给定的时间间隔之后,程序将循环并选择另一个NSString,显示包。



我的主要兴趣是如何创建NSStrings的这种包。使用NSDictionary或NSArray创建它们是可行的吗?

因为我刚刚开始,我希望有人能在我的研究中指出我的正确方向,所以我知道应该用什么工具来开始实验。



我非常感谢任何建议或示例代码。



谢谢!

解决方案

使用NSArray和NSDictionary。



  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];
...

您可以使用 [NSDictionary allKeys] / p>

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!

解决方案

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]

这篇关于如何创建随机选择的NSString“package” iPhone应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆