如何在视图加载时这样做,它会根据NSInteger的值显示一些内容? [英] How to make it so when the view loads, it displays something based on the value of an NSInteger?
本文介绍了如何在视图加载时这样做,它会根据NSInteger的值显示一些内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作一个测验应用,根据NSInteger myScore的值,在测验结束时显示一句话。我该怎么编码呢?任何帮助都会有所帮助'哈哈'。谢谢!
I am making a quiz app that displays a saying at the end of the quiz based on the value of the NSInteger myScore. How would I code this? Any help would be helpful 'haha'. Thanks!
推荐答案
使用存储您的诙谐评论的数组,并计算得分之外的数组索引。这样的事情:
Use an array that stores your witty remarks, and calculate an array index out of the score. Something like this:
NSArray *wittyNotes = [NSArray arrayWithObjects:
NSLocalizedString(@"Foo", nil), // 0 - 99
NSLocalizedString(@"Bar", nil), // 100 - 199
NSLocalizedString(@"Baz", nil), // 200 - 299
NSLocalizedString(@"Over 9000", nil), // 300 - ...
nil];
NSInteger index = myScore / 100;
if (index >= [wittyNotes count]) {
index = [wittyNotes count] - 1;
}
NSString *wittyNote = [wittyNotes objectAtIndex:index];
根据您的意愿,您可以使myScore-to-index计算更复杂。
Depending on your wishes you could make the myScore-to-index calculation more complicated.
这篇关于如何在视图加载时这样做,它会根据NSInteger的值显示一些内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文