My sliders are located on 10 different views. So, I want the user to be able to select a value with ratingSliderOne
, and then move on to "Page 2" and select another value etc. Those values should then be added up to a total
.h
@interface CBViewController : UIViewController
//Scorelabel
@property (nonatomic, readwrite) NSInteger theTotalScore;
@property (strong, nonatomic) IBOutlet UILabel *totalScoreLabel;
// Page 1
@property (strong, nonatomic) IBOutlet UISlider *ratingSliderOne;
@property (strong, nonatomic) IBOutlet UILabel *repeaterLabelOne;
// Page 2
@property (strong, nonatomic) IBOutlet UISlider *ratingSliderTwo;
@property (strong, nonatomic) IBOutlet UILabel *repeaterLabelTwo;
// Page 3
@property (strong, nonatomic) IBOutlet UISlider *ratingSliderThree;
@property (strong, nonatomic) IBOutlet UILabel *repeaterLabelThree;
// Page 4
@property (strong, nonatomic) IBOutlet UISlider *ratingSliderFour;
@property (strong, nonatomic) IBOutlet UILabel *repeaterLabelFour;
// Page 5
@property (strong, nonatomic) IBOutlet UISlider *ratingSliderFive;
@property (strong, nonatomic) IBOutlet UILabel *repeaterLabelFive;
// Page 6
@property (strong, nonatomic) IBOutlet UISlider *ratingSliderSix;
@property (strong, nonatomic) IBOutlet UILabel *repeaterLabelSix;
// Page 7
@property (strong, nonatomic) IBOutlet UISlider *ratingSliderSeven;
@property (strong, nonatomic) IBOutlet UILabel *repeaterLabelSeven;
// Page 8
@property (strong, nonatomic) IBOutlet UISlider *ratingSliderEight;
@property (strong, nonatomic) IBOutlet UILabel *repeaterLabelEight;
// Page 9
@property (strong, nonatomic) IBOutlet UISlider *ratingSliderNine;
@property (strong, nonatomic) IBOutlet UILabel *repeaterLabelNine;
// Page 10
@property (strong, nonatomic) IBOutlet UISlider *ratingSliderTen;
@property (strong, nonatomic) IBOutlet UILabel *repeaterLabelTen;
-(void)updateTotalScores;
- (IBAction)ratingSliderDidChange:(id)slider;
@end
.m
- (IBAction)ratingSliderDidChange:(id)slider
{
int sliderValue1 = self.ratingSliderOne.value;
int sliderValue2 = self.ratingSliderTwo.value;
int total = sliderValue1 + sliderValue2;
self.theTotalScore = total;
NSLog(@"%i, %i, %i", sliderValue1, sliderValue2, total);
[self updateTotalScores];
}
-(void)updateTotalScores{
if (_theTotalScore > 0) {
self.totalScoreLabel.text = [NSString stringWithFormat:@"%i", _theTotalScore];
NSLog(@"%i", _theTotalScore);
}
}
Currently, the NSLog(@"%i, %i, %i", sliderValue1, sliderValue2, total);
returns the correc values for each slider. But when you change from page 1 (i.e. ratingSliderOne) to page 2, it "forgets" the value of ratingSliderOne.
EDIT: Added all the code and clarified the question