我有一个问题正在引起我恐慌。 这完全是实时更新一架UITableViewCell,其价值为一架UISlider,位于另一颗UITableViewCell。
The problem
单元更新后 看来,牢房里的Label人的规模并不等于所代表的价值大小。 我将尽力作出更好的解释。
UISlider的最低月度为-100,最高值为100。 因此,表态第一次装满,cell.detailText.显示0.0%的巫师是ok,但当我搬动梯子,价值更大时,例如55.5%,标签不能保持这种额外性,显示“55.............>。
This is how I create the cell that holds de UISlider Value create the UISlider in the cellForRowAtIndexPath delegate method
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ProductCellIdentifier] autorelease];
cell.textLabel.text=@"Performance";
cell.detailTextLabel.text = [NSString stringWithFormat:@"%.1f%%", slider.value];
cell.tag=1002;
This is how I create de UISlider, in the cellForRowAtIndexPath method:
cell = [[[UITableViewCellalloc] initWithFrame:CGRectZero reuseIdentifier:ProductCellIdentifier] autorelease];
slider = [[UISlideralloc] initWithFrame:CGRectMake(90, 12, 200, 25)];
slider.maximumValue = 100;
slider.minimumValue = -100;
slider.continuous = TRUE;
[slideraddTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
[cell.contentView addSubview:slider];
cell.tag=0;
[slider release];
And this is what I do in the sliderChanged method in order to update the cell.
UITableViewCell *celda= (UITableViewCell *)[[self tableView] viewWithTag:1002];
celda.detailTextLabel.text = [NSString stringWithFormat:@"%.1f%%", slider.value];
I suspect that the solution is about the use of the reloadData method of the UITableView but not sure. I have tried inserting a self.tableView.reloadData
in the sliderChanged method but I got then the UISlider does not move and finally I got this exception:
Terminating app due to uncaught exception NSRangeException , reason: -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)
Thanks in advance for your help
Javi