开发者

Getting the value of multiple UISlider's in a UITableView

I have a UITableView with UISliders on each row. They all call the -(void) sliderValueChanged: (id)sender method.

I then have a label outside the UITableView that I populate with the value of the UISlider minus the CoreData value of Incomes. The problem is how do I take away the total slider values from the total income value. This is what I have so far but the slider value which I store in the NSNumber previousNumber variable does not work properly. Any help would great.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        UISlider *theSlider =  [[[UISlider alloc] initWithFrame:CGRectMake(55,20,220,45)] autorelease];
        theSlider.maximumValue=[self.totalIncomes floatValue];
        theSlider.minimumValue=0;       
        [theSlider addTarget:self action: @selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
        [cell addSubview:theSlider];
    }

    NSInteger section = [indexPath section];

            Categories  *category = (Categories *)[categoriesArray objectAtIndex:[indexPath row]];
            cell.textLabel.text = [NSString stringWithFormat:@"%@",[category name]];
            [category release];


    return cell;
}


-(void) sliderValueChanged: (id)sender
{
    UISlider *control = (UISlider *) sender;
    float value = control.value;
    float tot开发者_高级运维al = [self.totalIncomes floatValue];

    if ([self.previousNumber floatValue] < value) {
        total = total - (value - [self.previousNumber floatValue]);
    }
    else {
        total = total + ([self.previousNumber floatValue] - value);
    }

    self.totalIncomes = [NSNumber numberWithFloat: (float)total];
    NSLog(@"%.2f", [self.totalIncomes floatValue]);
    label.text = [NSString stringWithFormat:@"%.2f",[self.totalIncomes floatValue]];
    self.previousNumber = [NSNumber numberWithFloat:(float)value];
    //[self.tableView reloadData];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜