Reputation: 3106
I am trying to make an analysis app which calculates percentages of winners etc. Please see the attached picture:
So when there is a smash winner, the user clicks the UIStepper
and it should 'add 1' onto the smash winners total and number of rallies, and also update the percentage which is the winner divided by the number of rallies. If there was a drop winner after, then drop winner total gets updated along with the number of rallies and the smash and drop winner percentages.
Hopefully I have explained it well enough for you guys to understand :/
I am using this bit of code to update a generic winner:
- (IBAction)netChanged:(id)sender {
self.netLabel.text = [NSString stringWithFormat:@"%d",
[[NSNumber numberWithDouble:[(UIStepper *)sender value]] intValue]];
float net = [self.netLabel.text floatValue];
float rally = [self.rallyLabel.text floatValue];
float netPercentage = (rally == 0.0) ? 0 : net / rally * 100;
self.netPercentageLabel.text = [NSString stringWithFormat:@"%.2f%%", netPercentage];
}
My question is, what do I need to do in terms of code to update other percentages and rallies played when there is a winner?
Thanks.
Upvotes: 0
Views: 878
Reputation: 243146
You should be saving that data somewhere else, and not in the text
property of a UILabel
. Update the values, and then update the labels to reflect the updated values.
I highly recommend re-reading the documentation on Model-View-Controller.
Upvotes: 3