How to make it so when the view loads, it displays something based on the value of an NSInteger?
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.
精彩评论