我的滑块位于10个不同的视图中。因此,我希望用户能够选择ratingSliderOne
的值,然后转到" Page 34"然后选择另一个值等。然后将这些值加到总计
·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);
}
}
目前,NSLog(@"%i, %i, %i", sliderValue1, sliderValue2, total);
会返回每个滑块的correc值。但是当你从第1页(即ratingSliderOne)改为第2页时,它会忘记" ratingSliderOne的值。
编辑:添加了所有代码并澄清了问题
答案 0 :(得分:0)
- (IBAction)ratingSliderDidChange:(id)slider
是委托回调。每次移动或屏幕上连接的任何其他滑块移动时都会触发。
听起来你需要的是在这个回调中获取页面上每个滑块的值并每次创建总数。像这样:
- (IBAction)ratingSliderDidChange:(id)slider
{
int total = 0;
total += self.ratingSliderOne.value;
total += self.ratingSliderTwo.value;
// etc ....
self.theTotalScore = total;
NSLog(@"%i", _theTotalScore);
[self updateTotalScores];
}