UIslider价值问题
|
我在表格视图中有一个滑块。在滑块的动作方法中,我做了一些计算并重新加载了表格。当表格第二次重新加载时,它将滑块值设置为其最小值。
谁能知道为什么会发生这个奇怪的问题。
提前致谢!
码:
- (IBAction)sliderAction:(id)sender
{
UISlider* durationSlider = sender;
float gmval,finalCalculationValue;
float tempgmValue=[self.gmValue floatValue];
gmval=durationSlider.value;
tempgmValue=gmval/tempgmValue;
finalCalculationValue=tempgmValue/100;
tempgmValue=finalCalculationValue*[self.gmValue floatValue];
self.gmValue=[NSString stringWithFormat:@\"%0.f\",tempgmValue];
self.label.text=[NSString stringWithFormat:@\"%f\",tempgmValue];
[self.tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tbleView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @\"MyIdentifier\";
UITableViewCell *cell;
UILabel *label
cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(cell == nil){
cell = [self reuseTableViewCellWithIdentifier:MyIdentifier withIndexPath:indexPath];
}
return cell;
}
}
-(UITableViewCell *)reuseTableViewCellWithIdentifier:(NSString *)identifier withIndexPath:(NSIndexPath *)indexPath {
CGRect cellRectangle;
cellRectangle = CGRectMake(0.0, 0.0, 320, 100);
UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:cellRectangle reuseIdentifier:identifier] autorelease];
UILabel *label1;
cellRectangle = CGRectMake(15.0, 50, 200, 20.0);
label1 = [[UILabel alloc] initWithFrame:cellRectangle];
label1.tag = 5; label1.textAlignment = UITextAlignmentCenter;
[label1 setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:label1];
[label1 release];
UISlider *gmSlider=[[UISlider alloc]initWithFrame:CGRectMake(13, 20, 180, 21)]; gmSlider.tag=2003; gmSlider.backgroundColor = [UIColor clearColor];
gmSlider.continuous = YES;
gmSlider.minimumValue=10;
gmSlider.maximumValue=200; gmSlider.value=@\"100\"; [gmSlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
[cell.contentView addSubview:gmSlider];
}
return cell;
}
没有找到相关结果
已邀请:
3 个回复
荆怖赡
埃庐
稀瓣囊
时,您都要设置滑块的值。您已将该值设置为新计算的值,而不是常数100。