I have a question that drives me crazy. It's all about updating in real time a UITableViewCell with a UISlider value that is inside another UITableViewCell.
Problem
The cell is updated, but it seems that the size of the label in the cell is not added to the size of the displayed value. I will try to explain better.
UISlider has a minimum value of -100 and a maximum value of 100. Thus, when I first load the TableView, cell.detailText.text shows 0.0%, the witch displays normally, but when I move the slider and the value is greater, for example 55.5%, the label is not can hold these extra characters and the display shows "55 ....."
This is how I create a cell that contains a UISlider Value, creates a UISlider in the delegate method cellForRowAtIndexPath
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 a 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 to update the cell.
UITableViewCell *celda= (UITableViewCell *)[[self tableView] viewWithTag:1002]; celda.detailTextLabel.text = [NSString stringWithFormat:@"%.1f%%", slider.value];
I suspect the solution is to use the reloadData method of the UITableView, but not sure. I tried to insert self.tableView.reloadData in the self.tableView.reloadData method, but I got it, then UISlider is not moving, and finally I got this exception:
Application termination due to an uncaught exception "NSRangeException", reason: '- [NSCFArray objectAtIndex:]: index (0) outside bounds (0)'
Thank you in advance for your help.
Javi