0

I have two labels(total and price) and two textfields(quantity and type) in a cell.If I change the quantity textfield corresponding total label should change. And i am doing it. But the quantity functionality is taken only for last indexpath.row and I need to do in all row values in a cell.

    UIButton *btnCancel = (UIButton *)[Cell viewWithTag:105];
    UILabel *serialNumber = (UILabel *)[Cell viewWithTag:100];
    serviceType = (IQDropDownTextField *)[Cell viewWithTag:101];
    unitPrice = (UILabel *)[Cell viewWithTag:102];
    quantity = (UITextField *)[Cell viewWithTag:103];
    total = (UILabel *)[Cell viewWithTag:104];

    [btnCancel addTarget:self action:@selector(cancelButtonPressed:) forControlEvents:UIControlEventTouchDown];

    serialNumber.text = [NSString stringWithFormat:@"%i.",(indexPath.row+1)];

    serviceType.text =[NSString stringWithFormat:@"%@",serviceArray[indexPath.row]];
    unitPrice.text = [NSString stringWithFormat:@"%@",unitArray[indexPath.row]];
    quantity.text = [NSString stringWithFormat:@"%@",quantityArray[indexPath.row]];
    price = [[unitPrice text] intValue] * [[quantity text] intValue];
    (total.text = [NSString stringWithFormat:@"%d",price]);

    [serviceType setItemList:dropDownItemArray];

    [quantity addTarget:self
                 action:@selector(textFieldDidBeginEditing:)
       forControlEvents:UIControlEventEditingChanged];

    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(150, 0, 20, 21)];
    label1.text = @"Total Amount";
    label1.font = [UIFont fontWithName:@"HelveticaNeue" size:12];
    label1.backgroundColor = [UIColor clearColor];
    label1.textColor = [UIColor colorWithRed:62/255.0f green:68/255.0f blue:75/255.0f alpha:1.0f];
    [label1 sizeToFit];
    [tableView.tableFooterView addSubview:label1];

    totalAmount = [[UILabel alloc] initWithFrame:CGRectMake(235, 0, 80, 21)];
    totalAmount.text = @"";
    totalAmount.font = [UIFont fontWithName:@"HelveticaNeue" size:12];
    totalAmount.backgroundColor = [UIColor clearColor];
    totalAmount.textColor = [UIColor colorWithRed:62/255.0f green:68/255.0f blue:75/255.0f alpha:1.0f];
    [totalAmount sizeToFit];
    [tableView.tableFooterView addSubview:totalAmount];

    int count=20;

    for(int i = 0; i <[taxType count]; i++){
        UILabel *label =  [[UILabel alloc] initWithFrame: CGRectMake(175,count,0,0)];
        UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(235,count,0,0)];
        label.text =[NSString stringWithFormat:@"%@",taxType[i]];
        label.font = [UIFont fontWithName:@"HelveticaNeue" size:12];
        label.textColor = [UIColor colorWithRed:62/255.0f green:68/255.0f blue:75/255.0f alpha:1.0f];
        [label sizeToFit];
        label1.text =[NSString stringWithFormat:@"%@",taxAmount[i]];
        label1.font = [UIFont fontWithName:@"HelveticaNeue" size:12];
        label1.textColor = [UIColor colorWithRed:62/255.0f green:68/255.0f blue:75/255.0f alpha:1.0f];
        [label1 sizeToFit];
        count+=20;
        [tableView.tableFooterView addSubview:label];
        [tableView.tableFooterView addSubview:label1];


        }

    return Cell;

}

- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    return 40;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{

    price = [[unitPrice text] intValue] * [[quantity text] intValue];
            (total.text = [NSString stringWithFormat:@"%d",price]);
            (totalAmount.text =[NSString stringWithFormat:@"%d",price]);
}
thedp
  • 8,350
  • 16
  • 53
  • 95

0 Answers0