开发者

How to make it so when the view loads, it displays something based on the value of an NSInteger?

开发者 https://www.devze.com 2023-02-10 12:09 出处:网络
I am making a quiz app that displays a saying at the end of the quiz based o开发者_如何学运维n the value of the NSInteger myScore. How would I code this? Any help would be helpful \'haha\'. Thanks!Use

I am making a quiz app that displays a saying at the end of the quiz based o开发者_如何学运维n 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];

Depending on your wishes you could make the myScore-to-index calculation more complicated.

0

精彩评论

暂无评论...
验证码 换一张
取 消